I’m new to jQuery and I’m trying to work a solution that will be able to play sound files on most browsers. I have a working piece of code using jQuery and the audio support of HTML5. It will support most of the new browsers but won’t work with older browsers.
Is there a jQuery plugin that could work with the older browsers. Worst case scenario, I can convert the mp3 files to swf and try to play them using jQuery, if possible.
Here’s my code
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var sound = $("#sound")[0];
$("#play").mouseover(function() {
sound.play();
}).mouseleave(function(){
sound.pause();
sound.currentTime = 0;
});
});
</script>
</head>
<body>
<audio id="sound">
<source src="sound.ogg" type="audio/ogg" />
<source src="sound.mp3" type="audio/mp3" />
Your browser doesn't support HTML5.
</audio>
<span id="play">Mouse over to play sound</span>
</body>
`
Checkout the following projects:
All of them will use Flash on older browsers if needed.