using audio context manager function (#243)

* using audio context manager function

* updated pxt reference

* trigger build
This commit is contained in:
Peli de Halleux 2018-01-18 13:53:33 -08:00 committed by GitHub
parent ef5b4172e8
commit a60427e2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 22 deletions

View File

@ -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

View File

@ -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--;
});
}
}

View File

@ -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"

View File

@ -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() {