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
@ -5,7 +5,7 @@
|
||||
This repo contains the editor target hosted at https://d541eec2-1e96-4b7b-a223-da9d01d0337a.pxt.io/
|
||||
|
||||
LEGO Auth: https://src.education.lego.com/groups/ev3-makecode (use Google Authenticator)
|
||||
LEGO Chat: https://chat.internal.education.lego.com/make-code/channels/town-square
|
||||
LEGO Chat: https://chat.internal.education.lego.com/make-code/channels/town-square
|
||||
|
||||
## Local Dev setup
|
||||
|
||||
|
@ -291,6 +291,9 @@ namespace music {
|
||||
export function playSoundEffect(sound: Sound) {
|
||||
if (!sound || numSoundsPlaying >= soundsLimit) return;
|
||||
numSoundsPlaying++;
|
||||
control.runInBackground(() => {sound.play(); numSoundsPlaying--;});
|
||||
control.runInBackground(() => {
|
||||
sound.play();
|
||||
numSoundsPlaying--;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.15.7",
|
||||
"pxt-core": "3.0.11"
|
||||
"pxt-core": "3.0.12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
@ -16,25 +16,8 @@ namespace pxsim.SoundMethods {
|
||||
return incr(buf)
|
||||
}
|
||||
|
||||
export function uint8ArrayToString(input: Uint8Array) {
|
||||
let len = input.length;
|
||||
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 play(buf: RefBuffer) {
|
||||
return pxsim.AudioContextManager.playBufferAsync(buf);
|
||||
}
|
||||
|
||||
export function stop() {
|
||||
|
Loading…
Reference in New Issue
Block a user