Ho un progetto con Django Sto lavorando su dove voglio trasmettere alcuni file mp3.Tubo rotto durante lo streaming
Ho questo stesso problema: Streaming mp3 files with django, read from a page with <audio>
Mi spiego: io voglio flusso di ogg con Django, e con una <audio>
tag nella mia pagina html
ho un url del tipo domain.tld/song/show/X/
, dove X
è l'id della mia canzone. Posso eseguire lo streaming con VLC (direttamente con il percorso del file), posso eseguire lo streaming durante il test, (scrivo ciò che ricevo e lo leggo con VLC).
Ma quando ho aperto il mio browser e caricare la mia home page domain.tld
dove ho e <\audio\>
balise con url domain.tld/song/show/1/
, ottengo un grande tubo rotto, come se il mio cliente ha chiuso la connessione.
Ho letto su altri post che alcuni problemi sono stati risolti quando hanno messo il server in produzione. Quindi spingo la mia app sul server, uso apache, con il django.wgsi
come su djangoproject.com.
Sto eseguendo python 2.7.3 su Debian 7 con Django versione 1.5. c'è il mio codice:
Song/views.py
def playAudioFile(request, pk):
f = get_stream_song(pk)# return a pipe from pipes.Template
l = f.read() # the file is an ogg get by pydub.com
f.close()
size_read = 550000
sr = size_read
while sr == size_read:
print "rep"
r = l[:size_read]
l=l[size_read:]
sr = len(r)
yield r
time.sleep(0.1)
#url : ~/song/show/X/
#@login_required
def show_song(request, pk):
return StreamingHttpResponse(playAudioFile(request, pk), mimetype='audio/ogg',)
Nel mio HTML, devo solo che:
<audio controls height="100" width="100" preload="auto">
<source src="/.../song/show/1/" type="audio/ogg">
<embed height="50" width="100" src="/.../song/show/1/">
</audio>
L'errore si presenta come:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 86, in run
self.finish_response()
File "/usr/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response
self.write(data)
File "/usr/lib/python2.7/wsgiref/handlers.py", line 215, in write
self._write(data)
File "/usr/lib/python2.7/socket.py", line 324, in write
self.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 104] Connection reset by peer
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 46392)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 593, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/lumy/SPhoque/SonoPhoque/SoPhoque/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 150, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 704, in finish
self.wfile.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
I ottenuto questo due volte ogni volta che provo a trasmettere.
Edit 15h 29/05:
Ho fatto quello che Rahan suggerito: Guardando Firebug e Firefox debugger:
Il cliente fa:
GET 1 200 OK localhost:8000 537.1KB 4.71s
Headers
Response Headersview source
Date Wed, 29 May 2013 13:08:54 GMT
Server WSGIServer/0.1 Python/2.7.3
Content-Type audio/ogg
Request Headersview source
Host localhost:8000
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20100101 Firefox/10.0.12 Iceweasel/10.0.12
Accept audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Connection keep-alive
Range bytes=0-
Referer http://localhost:8000/
e dettagli dire che la dimensione totale per tutti i documenti è 1 MB (526 KB dalla cache)
tuo client/il browser sta terminando la connessione. Devi controllarlo. – Rohan
@Rohan con wireshark? sul debugger firefox una risposta get 200 per l'url /.../song/show/1/ – Lumy
Può usare wireshark o anche controllare il debugger FF se c'è qualcosa. – Rohan