I’m trying to create my own audio player. I’ve checked it in Google Chrome and everything is working good. But when I try to use it in Firefox and Opera (last versions) it does not. For example I have:
<!DOCTYPE html>
<head>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<div id="play">click me</div>
<audio class="tr_audio">
<source src="ogg/track1.ogg" type="audio/ogg; codecs='vorbis'">
<source src="track1.mp3" type="audio/mpeg; codecs='mp3'">
</audio>
<script>
$("#play").click(function() {
$("audio").get(0).play();
alert($("audio").get(0));
});
</script>
</body>
It work’s fine in Chrome, but doesn’t work in Opera and Firefox. Why?
Using your code and testing it in firefox made it clear that the problem was the codecs. The following lines were copied from the firefox console log:
Then, removing the
codecsspecification from thetypeattribute made it work in Firefox, Safari and Opera.I hope it helped. Cheers