Skip to content

Instantly share code, notes, and snippets.

@scottschiller
Forked from spadgos/gist:2561726
Created May 6, 2012 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottschiller/2623390 to your computer and use it in GitHub Desktop.
Save scottschiller/2623390 to your computer and use it in GitHub Desktop.
Recreating a SoundManager bug / fixed testcase
<html>
<head>
<!--
report URL: https://getsatisfaction.com/schillmania/topics/sound_playing_double
related SM2 fix/commit: https://github.com/scottschiller/SoundManager2/commit/013565dbb5abfc5bf0ab66b0246352ee3ca5cc02
-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Soundmanager test</title>
<!-- you'll have to correct the paths to SoundManager to get it working for yourself -->
<script>window.SM2_DEFER = true;</script>
<script src="script/soundmanager2.js"></script>
</head>
<body>
<button id="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);
}
}
var sm = window.soundManager = new window.SoundManager();
sm.url = './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.noSWFCache = true;
sm.onready(initialize);
sm.beginDelayedInit();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment