using audio context manager function (#243)
* using audio context manager function * updated pxt reference * trigger build
This commit is contained in:
		@@ -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() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user