Muted
$(document).ready(function() {
/* Create sound to be used later */
$('#audio').jWebAudio('addSoundSource', {
'url': 'resource/a.ogg',
'volume': 80,
'loop': true
});
/* Control sound with UI elements */
var isLoaded = false;
/* Play button */
$('#playBtn').click(function() {
if (!isLoaded) {
$('#audio').jWebAudio('load', function() {
// Remember that play should be called inside
// this callback function
$('#audio').jWebAudio('play');
$('#muted').removeAttr('disabled');
$('#volInput').val(
$('#audio').jWebAudio('options')
.volume);
$('#posInput').removeAttr('disabled');
/* Update position */
var total = $('#audio').jWebAudio('duration');
setInterval(function() {
var pos = 0;
if (total !== 0) {
pos = $('#audio').jWebAudio('seek')
/ total * 100;
}
$('#posInput').val(pos);
}, 100);
});
isLoaded = true;
} else {
$('#audio').jWebAudio('play');
}
$(this).attr('disabled', 'disabled');
$('#volInput').removeAttr('disabled')
$('#muted').removeAttr('disabled');
$('#pauseBtn').removeAttr('disabled');
$('#stopBtn').removeAttr('disabled');
$('#posInput').removeAttr('disabled');
});
/* Pause button */
$('#pauseBtn').attr('disabled', 'disabled').click(function() {
$('#audio').jWebAudio('pause');
$(this).attr('disabled', 'disabled');
$('#playBtn').removeAttr('disabled');
});
/* Stop button */
$('#stopBtn').attr('disabled', 'disabled').click(function() {
$('#audio').jWebAudio('stop');
$(this).attr('disabled', 'disabled');
$('#pauseBtn').attr('disabled', 'disabled');
$('#playBtn').removeAttr('disabled');
$('#posInput').attr('disabled', 'disabled').val(0);
});
/* Volume change */
$('#volInput').attr('disabled', 'disabled')
.attr('min', 0).attr('max', 100)
.change(function() {
$('#audio').jWebAudio('options', {
'volume': parseInt($(this).val())
});
});
/* Muted change */
$('#muted').attr('disabled', 'disabled').change(function() {
$('#audio').jWebAudio('options', {
'muted': $(this).is(':checked')
});
});
/* Seek position */
$('#posInput').attr('disabled', 'disabled')
.attr('min', 0).attr('max', 100)
.change(function() {
var pos = parseInt($(this).val());
if (pos !== 0) {
var total = $('#audio').jWebAudio('duration');
var seek = Math.ceil(total * pos / 100);
$('#audio').jWebAudio('seek', seek);
}
});
});