using audio context manager function (#243)
* using audio context manager function * updated pxt reference * trigger build
This commit is contained in:
parent
ef5b4172e8
commit
a60427e2cf
@ -291,6 +291,9 @@ namespace music {
|
|||||||
export function playSoundEffect(sound: Sound) {
|
export function playSoundEffect(sound: Sound) {
|
||||||
if (!sound || numSoundsPlaying >= soundsLimit) return;
|
if (!sound || numSoundsPlaying >= soundsLimit) return;
|
||||||
numSoundsPlaying++;
|
numSoundsPlaying++;
|
||||||
control.runInBackground(() => {sound.play(); numSoundsPlaying--;});
|
control.runInBackground(() => {
|
||||||
|
sound.play();
|
||||||
|
numSoundsPlaying--;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.15.7",
|
"pxt-common-packages": "0.15.7",
|
||||||
"pxt-core": "3.0.11"
|
"pxt-core": "3.0.12"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
@ -16,25 +16,8 @@ namespace pxsim.SoundMethods {
|
|||||||
return incr(buf)
|
return incr(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uint8ArrayToString(input: Uint8Array) {
|
export function play(buf: RefBuffer) {
|
||||||
let len = input.length;
|
return pxsim.AudioContextManager.playBufferAsync(buf);
|
||||||
let res = ""
|
|
||||||
for (let i = 0; i < len; ++i)
|
|
||||||
res += String.fromCharCode(input[i]);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function play(buf: RefBuffer, volume: number) {
|
|
||||||
if (!buf) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
return new Promise<void>(resolve => {
|
|
||||||
let url = "data:audio/wav;base64," + btoa(uint8ArrayToString(buf.data))
|
|
||||||
audio = new Audio(url)
|
|
||||||
audio.onended = () => resolve();
|
|
||||||
audio.onpause = () => resolve();
|
|
||||||
audio.play();
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stop() {
|
export function stop() {
|
||||||
|
Loading…
Reference in New Issue
Block a user