Merge branch 'master' of https://github.com/Microsoft/pxt-ev3
This commit is contained in:
commit
fee2329ca7
@ -257,7 +257,7 @@ namespace sounds {
|
|||||||
|
|
||||||
namespace music {
|
namespace music {
|
||||||
let numSoundsPlaying = 0;
|
let numSoundsPlaying = 0;
|
||||||
let soundsLimit = 3;
|
const soundsLimit = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays a sound
|
* Plays a sound
|
||||||
|
@ -6,6 +6,8 @@ namespace pxsim.music {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace pxsim.SoundMethods {
|
namespace pxsim.SoundMethods {
|
||||||
|
let numSoundsPlaying = 0;
|
||||||
|
const soundsLimit = 1;
|
||||||
|
|
||||||
export function buffer(buf: RefBuffer) {
|
export function buffer(buf: RefBuffer) {
|
||||||
return incr(buf)
|
return incr(buf)
|
||||||
@ -20,12 +22,17 @@ namespace pxsim.SoundMethods {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function play(buf: RefBuffer, volume: number) {
|
export function play(buf: RefBuffer, volume: number) {
|
||||||
|
if (!buf || numSoundsPlaying >= soundsLimit) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
return new Promise<void>(resolve => {
|
return new Promise<void>(resolve => {
|
||||||
let url = "data:audio/wav;base64," + btoa(uint8ArrayToString(buf.data))
|
let url = "data:audio/wav;base64," + btoa(uint8ArrayToString(buf.data))
|
||||||
let audio = new Audio(url)
|
let audio = new Audio(url)
|
||||||
audio.onended = () => {
|
audio.onended = () => {
|
||||||
resolve()
|
resolve();
|
||||||
|
numSoundsPlaying--;
|
||||||
}
|
}
|
||||||
|
numSoundsPlaying++;
|
||||||
audio.play()
|
audio.play()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user