I am trying to make a small application for streaming my mp3 files using the web interface, and I thought about playing and making the server side in python using django.
I want to have URLs such as / stream / ID to transfer mp3 corresponding to this ID. I made a presentation in django to serve these files using different methods, the last of which I tried to be described here
If I get / stream / ID from firefox, it plays mp3 directly using firefox-totem or some kind of plugin. If I use a page with my audio player with the same url as the source, it does not work at all (it works with a link to the mp3 file served by apache).
here is the code of my view (just send one test file)
def stream (request):
resp = HttpResponse (FileIterWrapper (open ('/.../ test.mp3', "rb")), mimetype = 'audio / mpeg')
resp ['Content-Length'] = os.path.getsize ("/.../ test.mp3")
resp ['Content-Disposition'] = 'filename = test.mp3'
return resp I cut the full path, this is not a problem.
When I look at the django output server, I noticed that every time the sound player tries, I get these 2 errors,
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 281, in run
self.finish_response ()
File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 321, in finish_response
self.write (data)
File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 417, in write
self._write (data)
File "/usr/lib/python2.6/socket.py", line 318, in write
self.flush ()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall (buffer (data, write_offset, buffer_size))
error: [Errno 104] Connection reset by peer
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 42891)
Traceback (most recent call last):
File "/usr/lib/python2.6/SocketServer.py", line 283, in _handle_request_noblock
self.process_request (request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
self.finish_request (request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
self.RequestHandlerClass (request, client_address, self)
File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py", line 562, in __init__
BaseHTTPRequestHandler .__ init __ (self, * args, ** kwargs)
File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
self.finish ()
File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
self.wfile.flush ()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall (buffer (data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
no problem / error when I directly join the stream url.
I tried the same in chrome (latest version with ffmpeg-extra installed), it works fine with mp3 from apache, but timeouts when using the stream url.
I tried setting up different headers in the answer, but without success. I am currently setting the content length, content type and content placement
I am looking for new ideas to try.
Thank you for your help!