2

I serve mp3 files from my application, using response.out, and it seems to work, BUT if the file is used in a html5 script or just played in web browser with a plugin, the mp3 file plays properly the first time, but if I try to rewind and play it again, it doesn't work anymore.

If I put the same file as a static file, then everything works fine.

This is the url of the file I serve from response.out (it only plays the first time, no rewind)

http://traki.eledit.net/media/ps/101_4.mp3

And here is the url of the same file served as a static page (this always works)

http://traki.eledit.net/static/test2.mp3

When both files are downloaded they are identical.

When I check the http headers of both files I also get almost identical results:

http://www.webconfs.com/http-header-check.php?url=http://traki.eledit.net/media/ps/101_4.mp3&submit=submit

http://www.webconfs.com/http-header-check.php?url=http://traki.eledit.net/static/test2.mp3&submit=submit

Does anyone have any idea of why the two files behave differently? What else should I do so that the file served with response.out behaves the same way as the file served as a static page?

tuoLarips
  • 170
  • 1
  • 10

2 Answers2

1

It seems likely that your browser is attempting to send range requests to your app when you rewind or seek, and your script isn't built to handle this. Verify this by checking the request logs, by logging your request headers in each request, and/or by checking using your browser's dev tools.

If this turns out to be the case, you should inspect and follow the browser's byte range headers and return only the requested parts of the file.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
0

Try changing the header to match the static mp3 file's Content-Type header.

self.response.headers['Content-Type'] = 'audio/mpeg'
self.respone.out.write(mp3_file)
CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43