зеркало из https://github.com/mozilla/shumway.git
Attempt to fix looping with audio tag; race3s example
This commit is contained in:
Родитель
81725ec74f
Коммит
6e9428703f
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче