Question

<div id='aplayer'></div>

js

$('#note').click(function() {
$('#aplayer').html("<embed src=" + music + " onended='test();'" + ">");
});

function test(){
    alert ('525');
}

audio is playing, but onended() doesn't work.
I also tried onplay and onplaying - without result.

Was it helpful?

Solution

If you can use HTML5, you should use the audio tag instead of the embed tag.

A JSfiddle exists here: http://jsfiddle.net/u6dbV/

<audio controls="controls" onpause="alert('Paused');" onended="alert('Ended');">
    <source src="http://www.jameshilldigital.net/testpage/borg.ogg" type="audio/ogg" />
  Your browser does not support the audio tag.
</audio>

This method also gets you a ton of awesome usage through the HTML5 Audio Tag's API:

http://html5doctor.com/native-audio-in-the-browser/

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio

If you're looking for a programmatic example, I have a little audio player here: https://github.com/daekano/beard/blob/master/app/js/beard.js

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top