Position: 0
Total:0
Description:
Seek the position of sound.
Result:
Play with the given position.
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; playing = true; $('#btn')[0].disabled = false; // update position 10 times per second setInterval(updatePos, 100); }, 'loop': true, 'fadeIn': true, 'fadeOut': true, 'fadeInTime': 5 }); } 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)); } function play() { if (playing) { // pause $('#btn').text('Play'); $('#audio').jWebAudio('stop'); } else { // play $('#btn').text('Stop'); $('#audio').jWebAudio('play'); } playing = !playing; }