3 ms·
The most efficient ambient sound generator : setInterval(function(){$('#btn'+(1+Math.floor(Math.random()*21))).trigger('click');},1000) Very powerful, rem
by throwaway8974 11y ago
The most efficient ambient sound generator :
setInterval(function(){$('#btn'+(1+Math.floor(Math.random()*21))).trigger('click');},1000)
Very powerful, remarkably simple to use.
- gniquil 11y agoGot 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();