HTML5 音频流
之前有一些关于 stackoverflow 的讨论,但从我所看到的来看,没有任何内容真正回答这个问题。
我正在尝试实现一个流音频网络应用程序。与 WFMU 对其播放器所做的几乎相同 (http://wfmu.org/html5/player.php< /a>)。
我从他们的流中所能弄清楚的是,他们正在将流传输到 PHP 中,不知道以什么格式,然后将其提供给 jPlayer 以向客户端呈现 HTML5。
他们的工作非常棒,但我只是不确定他们如何将音频输入 PHP 以及他们在 PHP 中做什么以将其以 HTML5 可接受的格式呈现。
任何想法将不胜感激。
看起来 PHP 脚本只是回显音频文件 (http://blogfiles.wfmu.org/ DG/stream3.php)。
There has been some talk of this around stackoverflow before, but nothing really answered this question from what I have seen.
I am trying to implement a streaming audio web application. Almost identical to what WFMU has done with their player (http://wfmu.org/html5/player.php).
All I have been able to figure out from their stream is they are piping the stream into PHP, don't know in what format, and then feeding this to jPlayer for HTML5 presentation to the client.
They have this working awesome, but I am just unsure how they are feeding the audio into PHP and what they are doing within their PHP to present it in an acceptable format for HTML5.
Any ideas would be greatly appreciated.
It looks like the PHP script just echos out an audio file (http://blogfiles.wfmu.org/DG/stream3.php).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有要求必须使用 PHP。对于客户端来说,重要的是您发送适当的内容类型和实际内容。在本例中,音频/mpeg (MP3) 或 Firefox 的 OGG(目前不适用于它们,但绝对可以)。
我怀疑他们使用 PHP 来转发流的原因是他们使用 SHOUTcast 作为流媒体服务器。做了一些探索,我发现了这个: http://mp3stream.wfmu.org:8000/
注意当您在浏览器中点击该 URL 时,您会看到基本信息页面。但是,如果您使用音频播放器点击此按钮,您就会获得该流。 SHOUTcast 服务器根据用户代理字符串来决定这一点。如果它在用户代理中的任何位置包含“Mozilla”,则它返回此页面。如果没有,则返回流。因此,对于 HTML5 音频播放器,它将使用浏览器的用户代理(包含 Mozilla)并且无法访问流。我怀疑他们的 PHP 脚本可以解决这个问题。
PHP 脚本将使用 cURL,使用自己的用户代理(可以是任何内容,只要不是“Mozilla”)连接到流媒体服务器,然后将块逐块中继到点击 PHP 脚本的浏览器。一块酸橙派。
There is no requirement to use PHP. For the client, all that matters is you send the appropriate content type, and actual content. In this case, audio/mpeg (MP3), or OGG for Firefox (which, isn't working for them right now, but it definitely can).
I suspect the reason that they are using PHP to relay the stream, is that they are using SHOUTcast as the streaming server. Doing some poking around, I found this: http://mp3stream.wfmu.org:8000/
Note that when you hit that URL in your browser, you get the basic information page. However, if you hit this with an audio player, you get the stream. The SHOUTcast server decides this based on the User-Agent string. If it contains "Mozilla" anywhere in the User-Agent, then it returns this page. If it doesn't, then it returns the stream. So, for an HTML5 audio player, it would use the browser's User-Agent (which contains Mozilla) and would be unable to access the stream. I suspect their PHP script is what gets around the problem.
The PHP script would use cURL, connect to the streaming server with its own User-Agent (can be anything, as long as it isn't "Mozilla"), and relay chunk by chunk to the browser that hit the PHP script. Piece of key-lime-pie.