|
|
|
|
|
by gniquil
3939 days ago
|
|
Got too much on my hand var OVERLAP = 2500;
var RECENTLY_PLAYED_NODES_LENGTH = 21;
var recentlyPlayedNodes = [];
var audioDurationFix = function(audio) {
if ($(audio).attr('id') === 'ive-13') {
return 3.0;
}
return audio.duration;
}
var randomNode = function() {
var newNode = $('#ive-'+(1+Math.floor(Math.random()*$('audio').length)))[0];
if (recentlyPlayedNodes.indexOf(newNode) === -1) {
recentlyPlayedNodes.push(newNode);
if (recentlyPlayedNodes.length > RECENTLY_PLAYED_NODES_LENGTH) {
recentlyPlayedNodes.shift();
}
return newNode;
} else {
return randomNode();
}
}
var playNext = function() {
var audioNode = randomNode();
$(audioNode).on('timeupdate', function() {
if (audioNode.currentTime * 1000 > audioDurationFix(audioNode) * 1000 - OVERLAP) {
$(audioNode).off('timeupdate');
playNext();
}
});
audioNode.play();
}
playNext();
|
|