JQuery IE how to stop the <embed> element

I am currently trying to play various wav files on my website. I am currently using an HTML5 element <audio>, but I am also trying to get some backward compatibility since IE will not play wavs through the audio tag.

I created a javascript function that creates the corresponding sound object <embed>:

function createPreHtml5EmbedItem(callID, parent) {
            $("#sound").remove();
            var sound = $("<embed id='sound' controls='console' type='audio/wav' />");
            sound.attr('src', '/recording?id=' + callID);
            sound.attr('loop', false);
            sound.attr('hidden', false);
            sound.attr('autostart', true);
            parent.append(sound);
}

Everything works fine, but when I press another button, I would like to stop playing this sound element. In firefox, I can do this:

function stopAudioPreHtml5() {
    $("#sound").remove();
}

but for some reason this does not work in IE. Is there a way to stop the current item <embed>before I delete it?

+5
source share
4 answers

IE .stop(), .

DEMO.

function stopAudioPreHtml5() {
    var sound = $("#sound");
    if ($.browser.msie) {
       sound[0].stop();
    }
    sound.remove();
}
+5

, Soundfile iframe iframe jquery?!

+1
function createPreHtml5EmbedItem(callID, parent) {
            $("#sound").remove();
            var sound = $("<embed id='sound' controls='console' type='audio/wav' />");
            sound.attr('src', '/recording?id=' + callID);
            sound.attr('loop', false);
            sound.attr('hidden', false);
            sound.attr('autostart', true);
            $(parent).append(sound);
}

changed the add line and works well for me. By the way, if you use .stop (), and if there are so many built-in objects on the page, this will cause performance problems. But remove () will not.

0
source

I had problems in IE when I have an element that matches the javascript variable name.

In this case, your variable soundand the element you are creating with the identifiersound

I am trying to use a different variable name when creating and adding all attributes to an object, such as

var soundIE = $("<embed id='sound' controls='console' type='audio/wav' />");

soundIE.attr('src', '/recording?id=' + callID);
soundIE.attr('loop', false);
soundIE.attr('hidden', false);
soundIE.attr('autostart', true);
$(parent).append(soundIE);
0
source

All Articles