Position: 0
Total:0
Description:
Event called when sound plays to the end.
Result:
Alert 'finish' when sound plays to the end.
Code:
// duration is the length of sound, in seconds var duration = null; function onload() { $('#audio').jWebAudio('addSoundSource', { 'url': '../../examples/resource/a.ogg', 'preLoad': true, 'callback': function() { $('#audio').jWebAudio('play'); duration = $('#audio').jWebAudio('duration'); $('#totalSpan').text(Math.ceil(duration)); $('#posInput')[0].disabled = false; // update position 10 times per second setInterval(updatePos, 100); }, 'finish': function() { alert('Finished!'); } }); } function posChange() { var pos = Math.min($('#posInput')[0] .value / 100 * duration, duration); // set position $('#audio').jWebAudio('seek', pos); } function updatePos() { // get position var pos = $('#audio').jWebAudio('seek'); $('#posInput')[0].value = pos / duration * 100; $('#posSpan').text(Math.ceil(pos)); }