Answer the question
In order to leave comments, you need to log in
HTML5 audio and java
Good afternoon!
I'm trying to make a proxy for a wav stream from a webcam.
The class that does this looks like this:
public class AudioHandler extends HttpServlet {
public AudioHandler() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("audio/wav");
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Cache-Control", "no-cache");
//////////////////////////////////////
InputStream in = null;
OutputStream out = null;
try {
System.err.println("[audio] Get stream!");
// URL = http://localhost:8080/control/audio?cam=10
URL cam = new URL("http://192.168.10." + request.getParameter("cam") + "/audio.cgi");
URLConnection uc = cam.openConnection();
out = new BufferedOutputStream(response.getOutputStream());
in = uc.getInputStream();
byte[] bytes = new byte[8192];
int bytesRead;
while ((bytesRead = in.read(bytes)) != -1) {
out.write(bytes, 0, bytesRead);
}
} catch (IOException ex) {
// Disconnect detected
System.err.println("[audio " + request.getParameter("cam") + "] Audio client disconnected");
// Прерываем поток, иначе передача не будет остановена
Thread.currentThread().interrupt();
}
}
}
<audio src="/control/audio?cam=20" controls preload="none">
Your browser does not support the
audio element.
</audio>
Answer the question
In order to leave comments, you need to log in
In general, I wrote an applet - everything works.
Who cares - github.com/Neuronix2/IRIS-X-Player
It is not very clear from the message: so it turns out that in.read does not subtract? After 33 seconds, zero length returns all the time in the loop? It seems to me that at least it is necessary to flush the stream after write, especially since it is wrapped in BufferedOutputStream.
do it via WebAudio API.
The audio tag is not intended for audio streaming apparently.
Why don't OpenSource solutions for playing wav on Flash suit you?
etcs.ru/blog/as3/wav_player/stackoverflow.com/questions/668186/can-the-flash-player-play-wav-files-from-a-url
_
I tried to play in VLC - it gives the same 33 seconds. It seems that the matter is not in the player.
Stream headers look like this:
Connected to 192.168.10.20.
Escape character is '^]'.
GET /audio.cgi
HTTP/1.0 200 OK
Date: Wed Jan 6 20:20:27 2010
Server: GoAhead-Webs
Pragma: no-cache
Cache-Control: no-cache
Content-Type: audio/x-wav
RIFFWAVEfmt ▒>}data▒▒▒<▒< .... дальше идут данные
And I get it like this:
Trying 192.168.10.150...
Connected to 192.168.10.150.
Escape character is '^]'.
GET /control/audio?cam=20
RIFFWAVEfmt ▒>}data▒<▒<▒<▒<
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question