HTML5 音频流 [英] HTML5 Audio Streaming

查看:49
本文介绍了HTML5 音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前有一些关于 stackoverflow 的讨论,但从我所看到的来看,没有什么能真正回答这个问题.
我正在尝试实现流式音频 Web 应用程序.几乎与 WFMU 对其播放器所做的相同 (http://wfmu.org/html5/player.php).
我能够从他们的流中弄清楚他们正在将流传输到 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).

推荐答案

不需要使用 PHP.对于客户端,重要的是您发送适当的内容类型和实际内容.在这种情况下,音频/mpeg (MP3) 或 Firefox 的 OGG(现在不适合他们,但绝对可以).

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).

我怀疑他们使用 PHP 来中继流的原因是他们使用 SHOUTcast 作为流服务器.四处摸索,我发现了这个:http://mp3stream.wfmu.org:8000/

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/

请注意,当您在浏览器中点击该 URL 时,您将获得基本信息页面.但是,如果您使用音频播放器点击此按钮,则会收到流.SHOUTcast 服务器根据 User-Agent 字符串决定这一点.如果它在 User-Agent 的任何地方包含Mozilla",则它返回此页面.如果没有,则返回流.因此,对于 HTML5 音频播放器,它将使用浏览器的用户代理(包含 Mozilla)并且无法访问流.我怀疑他们的 PHP 脚本可以解决问题.

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.

PHP 脚本将使用 cURL,使用自己的 User-Agent 连接到流媒体服务器(可以是任何东西,只要它不是Mozilla"),然后将块一块块地中继到命中 PHP 的浏览器脚本.一块酸橙馅饼.

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.

这篇关于HTML5 音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆