在 Firefox 中使用 HTML5 音频播放 mp3 Shoutcast 流? [英] Playing mp3 Shoutcast streams with HTML5 audio in Firefox?

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

问题描述

我正在尝试播放带有 HTML5 音频的 mp3 声音广播电台.

I'm trying to play mp3 shoutcast stream radio stations with HTML5 audio.

我认为这无关紧要,但无论如何这里是代码:

I don't think it will be relevant but here is the code anyway:

var player = new Audio();
player.autobuffer = true;
player.src = "http://173.192.48.71:9048/;";
player.volume = 1;
player.play();

Shoutcast 检测到请求来自浏览器并返回无线电状态页面,所以我输入了;"在流的末尾强制服务器返回音频流而不是状态页面.这适用于 Chrome 和 Safari,但不适用于 Firefox.

Shoutcast detects that request comes from browser and returns radio status page, so I put ";" at the end of stream which forces server to return audio stream instead of status page. This works fine in Chrome and Safari, but not in Firefox.

由于某种原因,Firefox 将其检测为文本/纯文本内容并拒绝播放此错误:

Firefox for some reason detects this as text/plain content and refuses to play it with this error:

HTTP "Content-Type" of "text/plain" is not supported. 
Load of media resource http://173.192.48.71:9048/; failed.

我使用 Fiddler 检查从 Shotcast 服务器发送的内容,它清楚地说明内容类型:音频/mpeg".有没有办法强制 Firefox 播放带有 HTML5 音频的shoutcast 流?

I used Fiddler to inspect what is being sent from shoutcast server and it clearly states "content-type: audio/mpeg". Is there any way to force Firefox to play the shoutcast stream with HTML5 audio?

推荐答案

Adobe Flash Player 对 Shoutcast 的支持已中断两次(请参阅 此处在这里)在去年,所以这对我来说是一个非常重要的问题.

Adobe Flash Player support for Shoutcast has broken twice (see here and here) in the last year, so this is a really important issue for me.

我决定调查一下.

Shoutcast 没有使用标准的 HTTP,而是使用 ICY 协议,与 HTTP/1.0 大致相同.

Instead of using standard HTTP, Shoutcast uses ICY protocol, which is approximately the same as HTTP/1.0.

Shoutcast 发送的状态行是

The status line that Shoutcast sends is

ICY 200 OK

但 Mozilla 不理解此状态行的 ICY 部分,因此它假定响应是 HTTP/0.9(没有内容类型/标头).这样做的结果是流的主体包括 ICY 状态行和标题(即标题被 Mozilla 解析).因为没有内容类型,Mozilla 会进行一些媒体嗅探",并在内容的小偏移处发现有效的 MP3 帧,并且 <audio> 标签使用这个嗅探到的内容可以正确运行 -类型.

but Mozilla doesn't understand the ICY part of this status line, so it assumes that the response is HTTP/0.9 (which has no content type/headers). The upshot of this is that the body of the stream includes the ICY status line and headers (i.e the headers are not parsed by Mozilla). Because there's no content-type, Mozilla does a bit of "media-sniffing" and discovers valid MP3 frames at a small offset into the content and the <audio> tag functions correctly using this sniffed content-type.

现在出现了一个问题,该问题通过强制所有 HTTP/0.9 得到解决内容通过非标准端口(即非端口 80/443)转换为 text/plain 的内容类型.现在,当内容体被传递给 HTML 标签时,它已经有一个 text/plain 的内容类型,所以它不再被嗅探到是在此问题之前,而是 Mozilla 不允许播放.

Now along comes an issue that gets fixed by forcing all HTTP/0.9 content coming over non-standard ports (i.e. non-port 80/443) to a content-type of text/plain. Now, when the content body is passed to the HTML <audio> tag it already has a content-type of text/plain, so it is no longer sniffed as it was prior to this issue, and instead Mozilla doesn't allow it to be played.

好消息是我解决了这个烦恼,Mozilla 现在处理 ICY协议等同于 HTTP/1.0.这反过来意味着 Mozilla 可以解码标题并读取正确的内容类型 audio/mpeg 并恢复播放.

The good news is that I fixed this annoyance and Mozilla now treats ICY protocol as being equivalent to HTTP/1.0. This in turn means that Mozilla can decode the headers and read the correct content type audio/mpeg and playback is restored.

我的修复应该会在今年晚些时候进入 Mozilla24.

My fix should find its way into Mozilla24 later this year.

同时,如果您想在 Mozilla 中播放 Shoutcast,则需要通过端口 80 进行广播.

In the mean time, if you want to play Shoutcast in Mozilla, you'll need to broadcast over port 80.

这篇关于在 Firefox 中使用 HTML5 音频播放 mp3 Shoutcast 流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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