Commit 92720411 authored by wildfirecode's avatar wildfirecode

1

parent f017e7e6
let soundOn = true;
// let bgChannel: egret.SoundChannel;
// let loading = false;
let bgChannel: egret.SoundChannel;
let loading = false;
export const getSoundOn = () => {
return soundOn
}
//document.getElementById('bgmusic').duration
export const toggleSound = () => {
soundOn = !soundOn;
if(soundOn) {
document.getElementById('bgmusic')['play']();
}else {
document.getElementById('bgmusic')['pause']();
if (bgChannel) {
if (!soundOn) {
bgChannel.stop();
bgChannel = null;
}
} else {
if (soundOn) {
playBg();
}
}
// if (bgChannel) {
// if (!soundOn) {
// bgChannel.stop();
// bgChannel = null;
// }
// } else {
// if (soundOn) {
// playBg();
// }
// }
}
// export const playBg = async () => {
// if (bgChannel) return;
// if (loading) return;
// loading = true;
// RES.getResByUrl(window['musciURL'], (bg) => {
// bgChannel = bg.play();
// loading = false;
// }, this, RES.ResourceItem.TYPE_SOUND);
// }
export const playBg = async () => {
if (bgChannel) return;
if (loading) return;
loading = true;
const bg = await RES.getResAsync('bg_mp3');
bgChannel = bg.play();
loading = false;
}
export enum SoundType {
click = 'click',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment