Position: 0
Total:0
Description:
Set sound fade in and fade out effect.
Result:
No sound effect when first play, because fade in is not set then. Fade in effect when seek and fade out effect when stop or 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; playing = true; $('#btn')[0].disabled = false; // update position 10 times per second setInterval(updatePos, 100); $('#audio').jWebAudio('options', { 'fadeIn': true, 'fadeInTime': 5, 'fadeOut': true }); }, 'loop': true }); } 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; }