当新歌开始在Chrome和Firefox中使用音频html5标签时,播放流媒体音乐会停止

时间:2012-10-06 14:47:14

标签: html5 mp3 playback html5-audio ogg

我已经设置了一个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在IE使用mp3时使用ogg源这一事实有关。当播放192 kbps(听到音乐时)时,Opera 12似乎也存在问题,我切换到128然后它能够​​流畅地工作。

任何人都知道修复此问题吗?

感谢您的帮助!

2 个答案:

答案 0 :(得分:4)

将此作为临时黑客发布,直到有人给出更好的答案。

在Chrome中,当播放停止时会抛出MEDIA_ERR_DECODE,而在Firefox中它会停止而没有任何错误。

我将src更改为currentSrc,然后在play()onerror事件中调用onended,但声音有时会在恢复播放前中断。必须有更好的方法。

/* jQuery - run on document ready */
$(function ()
{
    var audioElement = $('#audioPlayer')[0];

    audioElement.onended = audioElement.onerror = function()
    {
        audioElement.src = audioElement.currentSrc;
        audioElement.play();
    };
});

答案 1 :(得分:-1)

你没有必要做上面提到的那么多事情^我在你的代码中看到的唯一问题是你刚写了自动播放。你必须使它成为autoplay = true;

相关问题