range request support in python/django

1,344 views
Skip to first unread message

Rebecca Koeser

unread,
Apr 7, 2014, 3:15:44 PM4/7/14
to jpl...@googlegroups.com
I'm trying to use jPlayer in a python/django application where I'm serving out audio content (MP3/M4A) from a repository that I can only access via APIs, so to support seeking within jPlayer I need to implement the HTTP Range support in my django code.  I've taken a stab at this, and I think I have the logic basically correct, but as far as I can tell, jPlayer does not like something about the headers that I'm returning - when I turned on error reporting, I started getting this message in the console:

Media URL could not be loaded. Check media URL is valid. 

I've read some of the other posts about range requests and the thread about php support, but so far that hasn't been enough for me to figure out what I'm doing wrong.  If it takes a while for my request to return, is there a timeout issue that could be at play here? 

For a request with a Range request of "bytes=0-" I'm  returning the following headers (tested against django runserver via curl -v):

< HTTP/1.0 206 PARTIAL CONTENT
< Date: Mon, 07 Apr 2014 19:04:57 GMT
< Server: WSGIServer/0.1 Python/2.7.6
< Content-Length: 114126372
< Content-Transfer-Encoding: binary
< Accept-Ranges: bytes
< Vary: Cookie
< Content-MD5: d31deda97a29f412b048b6169d8741fc
< Content-Range: bytes 0-114126372/114126372
< ETag: d31deda97a29f412b048b6169d8741fc
< Content-Type: audio/mpeg

For a request with range bytes=1500- I'm returning:

< HTTP/1.0 206 PARTIAL CONTENT
< Date: Mon, 07 Apr 2014 19:07:02 GMT
< Server: WSGIServer/0.1 Python/2.7.6
< Content-Length: 114124872
< Content-Transfer-Encoding: binary
< Accept-Ranges: bytes
< Vary: Cookie
< Content-Range: bytes 1500-114126372/114126372
< ETag: "d31deda97a29f412b048b6169d8741fc"
< Content-Type: audio/mpeg

Does anyone see anything wrong or missing here, or do you have any suggestions of other things I can try?  Is there any utility that I can use to validate my results, or is one browser easier than the others to test with first (I have noticed that the requests and behavior does differ from one browser to another).

These tests above are using Django with the development runserver, which I understand could be an issue, but I'm getting pretty much the same behavior for the same code running under apache.

Thanks in advance for any advice or help to get this working.

Mark Panaghiston

unread,
Apr 8, 2014, 12:12:16 PM4/8/14
to jpl...@googlegroups.com
Saying "the browser" is not much help... There are many and they all behave differently.

You should look at this header, it looks wrong to me
Content-Transfer-Encoding: binary

Rebecca Koeser

unread,
Apr 9, 2014, 5:59:22 PM4/9/14
to jpl...@googlegroups.com
Mark, thanks for replying and helping me to look at this again.

I dropped the content-transfer-encoding header you thought looked wrong, and I took another look at the thread discussing the php implementation of range request support which is linked from the jPlayer site - and I discovered that I was slightly off in my range calculations; now that I've made some corrections I'm getting better results.

I've been testing in Chrome, Firefox, and Safari on Mac OSX.  My implementation is now working quite well in Chrome, and jPlayer will now let me jump ahead in the track, and it downloads the new range and plays the audio without errors.  

I'm still getting weird results from Firefox and Safari (Safari in particular seems to send what seem to me strange range requests, and a lot of them).  Does anyone know, is this an indicator that something is still off in my range calculations, and perhaps they are just off in a way that Chrome tolerates?  Are these browser specific issues I should investigate elsewhere, rather than something to do with jPlayer itself?

Thanks for any advice or guidance you can provide.

Mark Panaghiston

unread,
Apr 10, 2014, 2:28:46 PM4/10/14
to jpl...@googlegroups.com
While it is possible that your range request is still not correct... Since some browsers are working, it may be worth reviewing your media encoding. Some browsers simply do not like some types of encoding options.

Try your system using some of our MP3 files. For example:
http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3

prathamesh juvatkar

unread,
Apr 30, 2014, 2:51:04 PM4/30/14
to jpl...@googlegroups.com

I am building a music player application with Django + nginx for which I need a backend which supports byte range requests.

Django is authenticating the media file correctly but django dev server does not support range requests (206 partial response). Nginx directly serves byte range requests after using this configuration, I verified that the response header has content range. However I am unable to forward the request from django to nginx, to serve the content.

I tried using X-Accel-Redirect in a django view but still the response header doesn't have content range the way it would have been if the file had been directly served by nginx.

  • Django dev server - Authentication done but no byte range support (response 200)
  • Nginx - No authentication, byte range request support (response 206)
  • Django view + X-Accel-Redirect + nginx - Authentication done but no byte range support (response 200)

So I am trying to find a way to authenticate using Django and provide support for byte range requests with nginx or another static file server.

Reply all
Reply to author
Forward
0 new messages