gabitzish
gabitzish

Reputation: 9691

change source to <audio> html5 element

I'm building a jquery/html5 audio player and I have some problems on changing the source to the audio tag. The method I've implemented works on all browsers except IE9.

Here is a sample of code:

audio = $("<audio>").attr("id", "audioElement")
                        .attr("preload", "auto")
                        .appendTo(player);

function addMp3Source(sourceUrl) {
    audio.empty();
    var newSrc = $("<source>").attr("src", config.tracksURL + sourceUrl).appendTo(audio);
}

On IE9, the source is changing, but when I'm playing the track, it's the old sound that plays. On other browsers works fine.

Any ideeas?

Upvotes: 1

Views: 5116

Answers (1)

Mark Pro Campos
Mark Pro Campos

Reputation: 364

function addMp3Source(sourceUrl) {
    audio.empty();
    var newSrc = $("<source>").attr("src", config.tracksURL + sourceUrl).appendTo(audio);
    /****************/
    audio[0].pause();
    audio[0].load();//suspends and restores all audio element
    /****************/
}

Upvotes: 1

Related Questions