Creating a Web Radio
I'd like to develop a web sample application that can send and read audio on the fly.
The idea is to develop a website with HTML5/JS. So, the admin part (in php or whatever server side language) will allow me to send audio from a mic.
Then, on the client side, the user can listen to the stream with the <audio>
tag开发者_StackOverflow for example.
Is it possible? Did anybody use a strong (open/free) solution doing that?
Thank you,
Regards.
Pretty much any solution you choose will suffer from bad acceptance on one device or another, and web-based solution is even worse (as extensively pointed out by everybody).
If you want to cover the largest audience possible, set up a streaming server like Icecast and broadcast over MP3 and/or OGG (both is better). Pretty much every internet connected device with reasonable capabilities will be able to play streaming audio, so let the user pick the appropriate player or its favorite one.
http://web.psung.name/zeya/ - this app transcodes your music on the fly and streams it using HTML5. Maybe this will help a little bit ;)
There is a specification for interacting with devices, such as microphones, but it is early days and I'm not aware of any support for it.
If you want something that can interact with a mic today, look to Adobe Flash.
I don't think that you can do something like this with just JavaScript and HTML5. And if we could, we would most likely have to wait a long while before clients could use it in there browser. Like David said, Flash would work, the problem with that is: A) a lot of devices wouldn't support it and B) Flash is far from free. There are other ways of doing what you described but they would require other programming or at least other plugins. The only other alternative I can think of is Silverlight from Microsoft, free and not overly hard to use, it does have mic support, not sure how great it is though. Hope this helps.
The HTML audio tag does not specify any particular codec, so browser vendors are free to choose their own. Currently, none support a streaming format, although that could happen. As to recording, I'm not sure you'd really want to support unlimited recording from the browser, because you'd have concurrency issues? Would you really allow everybody to record at once?
It seems to make more sense to have a limited access to recording a streaming media session on the server, and then allow archived access to that through the browser. The retrieval could be easily performed with the HTML AUDIO tag, but essentially we've just invented the podcast.
It would be possible to manipulate audio tags to "stream" content, but there'd have to be a buffer of a couple seconds (at least). Re-set the source of the tag to a URL which provides the next couple seconds every couple seconds (not static files of course, but served dynamically from the stream). Admin side I think you're stuck with a plugin since you need mic access.
I think that what you are proposing is doable in theory, but in practice web clients and standards are still not really mature enough yet. For instance, check out this interesting blog about audio synthesis in JavaScript.
Now, for the theory:
Alternative 1: Wait for browsers to add support for a streaming audio format (typically, the audio tag currently supports WAV, OGG and/or MP3).
Alternative 2: Implement streaming yourself...
For the server side (the "mic" audio input thing) I assume you are free to do pretty much whatever you want. For instance, it should be possible to not actually connect the mic to the server, but rather let the server run some sort of transcoder process from another source/server. Then you can have a CGI/FastCGI application that web clients connect to to get the latest stream window (part of the stream, say 1-5 seconds?).
On the web client side, you can probably use the audio tag and control it from JavaScript to update it periodically with new stream windows. Queuing of audio samples is not supported, so you would have to come up with some sort of custom synchronization mechanism. One solution could be to use two simultaneous audio samples that cross-fade (thus minimizing clicks & hickups resulting from inaccurate timing).
This document on the Apple website might be what you are looking for. It recommends using HTTP Live Streaming for devices like the iPad, iPhone and the iPod Touch: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html
Might be what you are after.
精彩评论