Merge pull request #1060 from kchadha/fix-sound-metadata

Update sound metadata and retrieve mp3 correctly from storage
This commit is contained in:
kchadha 2018-04-17 11:02:56 -04:00 committed by GitHub
commit 47a2d76a14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -22,6 +22,13 @@ const loadSoundFromAsset = function (sound, soundAsset, runtime) {
{data: soundAsset.data} {data: soundAsset.data}
)).then(soundId => { )).then(soundId => {
sound.soundId = soundId; sound.soundId = soundId;
// Set the sound sample rate and sample count based on the
// the audio buffer from the audio engine since the sound
// gets resampled by the audio engine
const soundBuffer = runtime.audioEngine.getSoundBuffer(soundId);
sound.rate = soundBuffer.sampleRate;
sound.sampleCount = soundBuffer.length;
return sound; return sound;
}); });
}; };

View file

@ -38,10 +38,8 @@ const deserializeSound = function (sound, runtime, zip, assetFileName) {
log.error(`Could not find sound file associated with the ${sound.name} sound.`); log.error(`Could not find sound file associated with the ${sound.name} sound.`);
return Promise.resolve(null); return Promise.resolve(null);
} }
let dataFormat = null; const dataFormat = sound.dataFormat.toLowerCase() === 'mp3' ?
if (sound.dataFormat.toLowerCase() === 'wav') { storage.DataFormat.MP3 : storage.DataFormat.WAV;
dataFormat = storage.DataFormat.WAV;
}
if (!JSZip.support.uint8array) { if (!JSZip.support.uint8array) {
log.error('JSZip uint8array is not supported in this browser.'); log.error('JSZip uint8array is not supported in this browser.');
return Promise.resolve(null); return Promise.resolve(null);