diff --git a/examples/racing/race3s.fla b/examples/racing/race3s.fla new file mode 100644 index 000000000..8d978f2ba Binary files /dev/null and b/examples/racing/race3s.fla differ diff --git a/examples/racing/race3s.swf b/examples/racing/race3s.swf new file mode 100644 index 000000000..1204ba047 Binary files /dev/null and b/examples/racing/race3s.swf differ diff --git a/src/flash/media/SoundChannel.js b/src/flash/media/SoundChannel.js index 4740f0206..5ad514d48 100644 --- a/src/flash/media/SoundChannel.js +++ b/src/flash/media/SoundChannel.js @@ -64,29 +64,33 @@ var SoundChannelDefinition = (function () { this._registerWithSoundMixer(); this._position = startTime; var self = this; + var lastCurrentTime = 0; var element = document.createElement('audio'); if (!element.canPlayType(soundData.mimeType)) { console.error('ERROR: \"' + soundData.mimeType +'\" ' + 'type playback is not supported by the browser'); return; } + element.loop = loops > 0; // starts loop played if at least one is specified element.src = "data:" + soundData.mimeType + ";base64," + base64ArrayBuffer(soundData.data); element.addEventListener("loadeddata", function loaded() { element.currentTime = startTime / 1000; element.play(); }); element.addEventListener("timeupdate", function timeupdate() { - self._position = element.currentTime * 1000; + var currentTime = element.currentTime; + if (loops && lastCurrentTime > currentTime) { + --loops; + if (!loops) // checks if we need to stop looping + element.loop = false; + if (currentTime < startTime / 1000) + element.currentTime = startTime / 1000; + } + self._position = (lastCurrentTime = currentTime) * 1000; }); element.addEventListener("ended", function ended() { - if (!loops) { - this._unregisterWithSoundMixer(); - self.dispatchEvent(new flash.events.Event("soundComplete", false, false)) - return; - } - loops--; - element.currentTime = startTime / 1000; - element.play(); + self._unregisterWithSoundMixer(); + self.dispatchEvent(new flash.events.Event("soundComplete", false, false)) }); this._element = element; }, diff --git a/src/swf/sound.js b/src/swf/sound.js index edd6da75d..d0e18d912 100644 --- a/src/swf/sound.js +++ b/src/swf/sound.js @@ -85,7 +85,7 @@ function defineSound(tag, dictionary) { break; case SOUND_FORMAT_MP3: packaged = { - data: data.subarray(2), + data: new Uint8Array(data.subarray(2)), mimeType: 'audio/mpeg' }; break;