我已经设置了一个 IceCast2 服务器,它能够以 192 kbps 的速度流式传输 ogg 或 mp3。
在我使用的 html 中:
<audio controls autoplay>
<source src="http://site.com:8000/mount1.ogg" type="audio/ogg">
<source src="http://site.com:8000/mount2.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
但在 Chrome 22/Firefox 13 中,每当一首新歌开始播放时,播放器就会停止播放。在 IE10 中它继续播放没有任何问题。我认为这可能与以下事实有关:Chrome 和 Firefox 使用 ogg 源,而 IE 使用 mp3。 Opera 12 播放 192 kbps 时似乎也有问题(听音乐时会断断续续),我切换到 128 然后就流畅了。
有人知道解决这个问题的方法吗?
感谢您的帮助!
最佳答案
将此作为临时 hack 发布,直到有人给出更好的答案。
在 Chrome 中,当播放停止时抛出 MEDIA_ERR_DECODE
,而在 Firefox 中,它只是停止而没有任何错误。
我将 src
更改为 currentSrc
然后在 onerror
和 onended 中调用了
事件,但声音有时会在恢复播放之前中断。一定有更好的方法。play()
/* jQuery - run on document ready */
$(function ()
{
var audioElement = $('#audioPlayer')[0];
audioElement.onended = audioElement.onerror = function()
{
audioElement.src = audioElement.currentSrc;
audioElement.play();
};
});
关于html - 当一首新歌开始使用 Chrome 和 Firefox 中的音频 html5 标签时,播放流媒体音乐停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12760812/