Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing streaming music stops when a new song starts using audio html5 tag in Chrome and Firefox

I have setup an IceCast2 server which is capable of streaming ogg or mp3, both at 192 kbps.

In the html I use:

<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>

But in Chrome 22 / Firefox 13 every time a new song begins, the player stops playback. In IE10 it continues playing without any problem. I'm thinking this might have something to do with the fact that Chrome and Firefox use the ogg source while IE uses mp3. It seems there is also a problem with Opera 12 when playing 192 kbps (music is heard saccadated), I switched to 128 and then it worked fluently.

Anyone know a fix for this?

Thanks for your help!

like image 706
Răzvan Flavius Panda Avatar asked Oct 07 '22 10:10

Răzvan Flavius Panda


1 Answers

Posting this as a temporary hack until someone gives a better answer.

In Chrome MEDIA_ERR_DECODE is thrown when the playback stops, while in Firefox it just stops without any error.

I changed the src to currentSrc and then called play() in onerror and onended event, but the sound is sometimes interrupted before resuming play. There must be a better way.

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

    audioElement.onended = audioElement.onerror = function()
    {
        audioElement.src = audioElement.currentSrc;
        audioElement.play();
    };
});
like image 148
Răzvan Flavius Panda Avatar answered Oct 10 '22 02:10

Răzvan Flavius Panda