mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #908 from ericrosenbaum/bugfix/load-music-ext-safari
Fix music extension asset loading on safari
This commit is contained in:
commit
ad4b31263c
1 changed files with 16 additions and 3 deletions
|
@ -97,10 +97,23 @@ class Scratch3MusicBlocks {
|
||||||
_loadSound (fileName, index, bufferArray) {
|
_loadSound (fileName, index, bufferArray) {
|
||||||
if (!this.runtime.storage) return;
|
if (!this.runtime.storage) return;
|
||||||
if (!this.runtime.audioEngine) return;
|
if (!this.runtime.audioEngine) return;
|
||||||
|
if (!this.runtime.audioEngine.audioContext) return;
|
||||||
return this.runtime.storage.load(this.runtime.storage.AssetType.Sound, fileName, 'mp3')
|
return this.runtime.storage.load(this.runtime.storage.AssetType.Sound, fileName, 'mp3')
|
||||||
.then(soundAsset =>
|
.then(soundAsset => {
|
||||||
this.runtime.audioEngine.audioContext.decodeAudioData(soundAsset.data.buffer)
|
const context = this.runtime.audioEngine.audioContext;
|
||||||
|
// Check for newer promise-based API
|
||||||
|
if (context.decodeAudioData.length === 1) {
|
||||||
|
return context.decodeAudioData(soundAsset.data.buffer);
|
||||||
|
} else { // eslint-disable-line no-else-return
|
||||||
|
// Fall back to callback API
|
||||||
|
return new Promise((resolve, reject) =>
|
||||||
|
context.decodeAudioData(soundAsset.data.buffer,
|
||||||
|
buffer => resolve(buffer),
|
||||||
|
error => reject(error)
|
||||||
)
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(buffer => {
|
.then(buffer => {
|
||||||
bufferArray[index] = buffer;
|
bufferArray[index] = buffer;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue