This is my code for playing a html5 audio (which doesn’t work)
$('img.play_media').bind('click',function(){
src=$(this).attr("id"); $('audio[id=resource_audio]').children('source').attr("src","testuser/resources/"+src);
var audio= document.getElementById('resource_audio');
audio.play();
return false;
});
<audio id="resource_audio" >
<source src="" type="audio/mp3" />
</audio>
As you can see, I am trying to get the src on img click ,which is set to the image id and in opera I can see the play starting. But, the audio doesn’t play. Any help is appreciated.
Thanks.
Please provide the HTML for the img. I’ve cleaned up your code a bit, but probably won’t help with your problem:
You may also want to look at https://developer.mozilla.org/en/HTML/Element/audio.