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

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

问题描述

我正在尝试使用HTML5音频播放mp3 shoutcast流电台。

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检查从shoutcast服务器发送的内容,并清楚地说明内容类型:音频/ 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?

推荐答案

Adob​​e 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 /来解决纯。现在,当内容正文传递给HTML < audio> 标记时,它的内容类型为 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天全站免登陆