HTML5 音频流

发布于 2024-10-22 05:45:48 字数 515 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极度宠爱 2024-10-29 05:45:48

没有要求必须使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文