using audio context manager function (#243)
* using audio context manager function * updated pxt reference * trigger build
This commit is contained in:
		@@ -5,7 +5,7 @@
 | 
				
			|||||||
This repo contains the editor target hosted at https://d541eec2-1e96-4b7b-a223-da9d01d0337a.pxt.io/
 | 
					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 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
 | 
					## Local Dev setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user