mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Use new audio engine api to retreive and set sound buffers
This commit is contained in:
parent
44298fd71b
commit
25a0e2ffaf
1 changed files with 26 additions and 0 deletions
|
@ -333,6 +333,32 @@ class VirtualMachine extends EventEmitter {
|
|||
this.emitTargetsUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sound buffer from the audio engine.
|
||||
* @param {int} soundIndex - the index of the sound to be got.
|
||||
* @return {AudioBuffer} the sound's audio buffer.
|
||||
*/
|
||||
getSoundBuffer (soundIndex) {
|
||||
const id = this.editingTarget.sprite.sounds[soundIndex].soundId;
|
||||
if (id && this.runtime && this.runtime.audioEngine) {
|
||||
return this.runtime.audioEngine.getSoundBuffer(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a sound buffer.
|
||||
* @param {int} soundIndex - the index of the sound to be updated.
|
||||
* @param {AudioBuffer} newBuffer - new audio buffer for the audio engine.
|
||||
*/
|
||||
updateSoundBuffer (soundIndex, newBuffer) {
|
||||
const id = this.editingTarget.sprite.sounds[soundIndex].soundId;
|
||||
if (id && this.runtime && this.runtime.audioEngine) {
|
||||
this.runtime.audioEngine.updateSoundBuffer(id, newBuffer);
|
||||
}
|
||||
this.emitTargetsUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a sound from the current editing target.
|
||||
* @param {int} soundIndex - the index of the sound to be removed.
|
||||
|
|
Loading…
Reference in a new issue