Skip to content

Instantly share code, notes, and snippets.

@spadgos
Created April 30, 2012 19:19
Show Gist options
  • Save spadgos/2561726 to your computer and use it in GitHub Desktop.
Save spadgos/2561726 to your computer and use it in GitHub Desktop.
Recreating a SoundManager bug
<html>
<head>
<title>Soundmanager test</title>
<!-- you'll have to correct the paths to SoundManager to get it working for yourself -->
<script src="vendor/soundmanager/soundmanager2-nodebug.js"></script>
</head>
<body>
<button>Start test</button>
<script type="text/javascript">
function initialize() {
console.log('initializing');
var goneBack = false;
var urls = [
'https://api.soundcloud.com/tracks/44536323/stream?client_id=bcdd94de263f5ce5a929f7a53ee19be7',
'https://api.soundcloud.com/tracks/44536325/stream?client_id=bcdd94de263f5ce5a929f7a53ee19be7'
];
var sounds = urls.map(function (url, index) {
var options;
options = {
id: 'audio-' + index,
url: url,
autoLoad: false
};
options.onfinish = function () {
if (index === 0) {
console.log('sound0 has finished. sounds[0].pause, sounds[0].setPosition(0), sounds[1].setPosition(0), sounds[1].play()');
sounds[0].pause();
sounds[0].setPosition(0);
sounds[1].setPosition(0); // } HERE IS WHERE THE BUG HAPPENS! If these two lines are
sounds[1].play(); // } swapped, then everything is ok.
if (!goneBack) {
setTimeout(function () {
var pos = sounds[0].duration - 2000;
console.log('seeking back into sound0. sounds[1].pause, sounds[0].setPosition(%o) sounds[0].play', pos);
sounds[1].pause();
sounds[0].setPosition(pos);
sounds[0].play();
goneBack = true;
}, 2000);
} else {
setTimeout(function () {
console.log('pausing sound1');
sounds[1].pause(); // when this is executed, then it plays the sound double.
}, 2000);
}
}
};
return soundManager.createSound(options);
});
document.getElementById('button').onclick = function () {
sounds[0].play();
var intId = setInterval(function () {
if (sounds[0].readyState === 3) {
clearInterval(intId);
console.info('sound loaded');
begin();
} else {
console.info('waiting... sound not loaded yet');
}
}, 1000);
};
function begin() {
var pos = sounds[0].duration - 2000;
console.log('Setting position of sound0 to 2s before the end: %o', pos);
sounds[0].setPosition(pos);
}
}
window.SM2_DEFER = true;
var sm = window.soundManager = new window.SoundManager();
sm.url = '/vendor/soundmanager/swf/';
sm.flashVersion = 9;
sm.useFlashBlock = false;
sm.useHTML5Audio = false;
sm.defaultOptions.multiShot = false;
sm.allowPolling = true;
sm.flashPollingInterval = 80;
sm.useHighPerformance = true;
sm.wmode = 'transparent';
sm.beginDelayedInit();
sm.onready(initialize);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment