一年多来,我一直在使用 JW Player 5.7 在客户的网站上播放音频 mp3 文件,没有任何问题。我的客户刚接到一个电话,说音频没有播放。音频不再在 Chrome (v28)、Safari(v5 和 v6)和 IE9 中播放。它的工作方式与 Firefox (v23) 中的一样。我不知道它什么时候停止工作,因为我和我的客户通常都使用 Firefox。我不知道它是否与浏览器或其他什么有关。
突出的一件事是,使用开发人员工具,内容类型标头在 Firefox (audio/mpeg3) 中似乎是正确的,但在 Chrome、Safari 和 IE9 中设置为“text/html”。
这是一个网页链接,您可以在其中看到问题: http ://www.thebuzzmusiclibrary.com/music/display_album/20
使此配置有点独特的几件事:
jwplayer 代码是动态加载的,即当用户单击“箭头”图标之一时,jwplayer 代码通过 javascript 加载并开始播放,因为“autostart”设置为 true。
因为 mp3 文件位于目录根目录之上,所以“file”参数实际上是一个 PHP 函数,它实际上是下载文件。
这是动态加载的代码:
<div id="mediaplayer">This text will be replaced</div>
<script type="text/javascript">
jwplayer("mediaplayer").setup({
"file": "' + file + '",
"controlbar": "bottom",
"width": "220",
"height": "24",
"provider": "sound",
"autostart": "true",
"bufferlength": "2",
"modes": [ {type: "flash", src: "/js/player-licensed-5.7.swf"}, {type: "html5"}, {type: "download"} ]
});
这是下载 mp3 文件的 PHP 脚本的主要部分($mime 是 'audio/mpeg3')
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.$name.'"');
header('Content-Description: File Transfer');
header('Content-Length: '.$info['size']);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
while( ! feof($file))
{
echo fread($file, 2048);
}
static::close_file($file, $area);
exit;