Skip to Content
Menu
This question has been flagged
4 Replies
6736 Views

Hello,

I placed a video on a Odoo website homepage using HTML5 tags. The video size is arround 11 Mb. I can not play this video on iOS system only. I found the cause of the problem. For iOS, my web server need to support "byte-range requests" as see here : \http://stackoverflow.com/a/4762072

I put my video under an Apache Web server and I am able to play the video on iOS by using the URL to this video on Apache server. But, I would like to stock the video file on my Odoo custom module, then reach the video from my Odoo URL.

Is there a way to support "byte-range requests" on Odoo Web server?


Thanks

Avatar
Discard
Best Answer

In case anyone requires any help or advice on this issue. I managed to write a custom controller to stream mp4 video file to all devices including iOS mobile devices. See the code snippet below for streaming mp4 video file from odoo.  Hope the code works for you, but streaming mp4 file from odoo is not recommended because of odoo is not meant for streaming media and it will affect odoo's performance if the video request gets too much.

Thus, my recommended solution is to setup apache2 to serve the video media. The load speed of the video is drastically faster than loading from odoo. 

Hope this helps.

@http.route(['/mainvideo'], type='http', auth="public", website=True)
    def website_mainvideo(self, **post):
        cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
        mainvideo = ""
        with open("static/src/videos/homepage.mp4", 'rb') as mp4_file:
            mainvideo = mp4_file.read()
        headers = [('Content-Type', 'video/mp4'),('Accept-Ranges', 'bytes')]
        
        status = 200
        if request.httprequest.range:
            contentrange = request.httprequest.range.make_content_range(len(mainvideo))
            if contentrange.stop < len(mainvideo):
                status = 206
                headers.append(('Content-Range','bytes %s-%s/%s' % (str(contentrange.start), str(contentrange.stop), str(len(mainvideo)))))
            elif contentrange.stop > len(mainvideo):
                status = 416
                mainvideo = ""
                
        if status != 416:
            mainvideo = mainvideo[contentrange.start:contentrange.stop]
            headers.append(('Content-Length', len(mainvideo)))
        response = Response(mainvideo, status=status, headers=headers, content_type="video/mp4")
        return response

Avatar
Discard
Best Answer

Hi,

I just raised the same issue to Odoo. Unfrotunately the issue was not solved but just disabled to show the play button on iOS.

https://github.com/odoo/odoo/commit/5e3b471f4a67553d6f7525595b15dc3d7b4efb3f


This was the reply:

The explanation about your issue is:
HTTP servers hosting media files for iOS must support byte-range requests, which iOS
uses to perform random access in media playback. (Byte-range support is also
known as content-range or partial-range support.) But Odoo server doesn't support partial 
requests with accept-ranges.

So the fix was to unable the button play on IOS.
But we will try to improve it in master.
Thanks for your feedback.


Has anyone found a solution yet because I need this as well!

Do you maybe have some further information on the nginx "work around"
I cannot follow this and understand what actually is to do.

Thanks in advance!

Avatar
Discard
Best Answer

I do not think there is any way to support byte-range requests in Odoo server without modifications. You may be able to implement some of werkzeug's byte-range responses by designing a custom controller to handle your media. I have seen reference to byte-range handling in headers in werkzeug's docs however I have not seen a plug and play example for handling byte-range requests.


It took me quite a while to even determine why media was not loading on safari. I do not own an apple computer so using the developer tools is much more difficult. 


The simplest work around is on the same server you are hosting Odoo on you can define nginx or apache webserver to serve requests for Odoo using a reverse proxy. 


Define a specific set of paths that are handled exclusively by apache or nginx and host your media there. I have tested this and it works.


Another option is to use a CDN to host your media. And simply use a CDN that supports byte-range requests. Then just change the url on your Odoo server's html to point at your CDN. This approach has the additional benefit of lowering the number of requests on your server and frees up your bandwidth for other purposes.


Here is an example virtualhost config for apache. 


<VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName byterangetest.com
        DocumentRoot /var/www/media/
        ProxyPass /your_addon/static/src/vids !
        ProxyPass / http://byterangetest.com:8069/
        ProxyPassReverse / http://byterangetest:8069/
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
        ErrorLog ${APACHE_LOG_DIR}/error.log
Avatar
Discard
Author Best Answer

Any news? It is an important case to be able to show video on Apple devices...

Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
May 23
1757
0
Dec 16
3348
0
Mar 15
3358
0
Jan 22
1668
1
May 20
3082