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