Skip to content Skip to sidebar Skip to footer

Create A Html5 Audio And Play It Doesn't Work

I want create a html5 audio in dynamic and play it,here is the code: function playAnotherMusic(playUrl){ var audioElement = document.createElement('audio');

Solution 1:

You can't play mp3 files in firefox, it does not support them, you need an ogg version for firefox. Unless that changes, good to keep in mind.

Why doesn't Firefox support the MP3 file format in <audio>

Solution 2:

You need to append the audio element to the an existing element. This would be something like

document.getElementById("my_audio_div").appendChild(audioElement);

Idealy, this should be done before you add the event listener, but after setting all the attributes

Also try audio/mp3 instead: audioElement.setAttribute('type', 'audio/mp3');

Post a Comment for "Create A Html5 Audio And Play It Doesn't Work"