import { AudioComponent , EventManager , HTMLAudio , ResManager } from "../../framework" ; import { Audio } from "./Audio" ; import { AudioInterface } from "./interface/AudioInterface" ; /**
 * 背景音乐
 */ export class Bgm { private static DEFAULT_NICK = "default" ; private static mBgmAduio : Audio = new Audio ( ) ; private static isInit : boolean = false ; public static set volume ( volume ) { this . mBgmAduio . volume = volume ; } public static get volume ( ) : number { return this . mBgmAduio . volume ; } public static set muted ( muted ) { this . mBgmAduio . muted = muted ; } public static get muted ( ) : boolean { return this . mBgmAduio . muted ; } public static set mutedOffset ( mutedOffset ) { this . mBgmAduio . mutedOffset = mutedOffset ; } public static get mutedOffset ( ) : boolean { return this . mBgmAduio . mutedOffset ; } public static get audioMap ( ) : Map < string , AudioInterface > { return this . mBgmAduio . mAudioMap ; } public static init ( voiceVolume ? , isOpenVoice ? ) { if ( this . isInit ) { return ; } this . isInit = true ; EventManager . on ( "背景音量改变" , this . bgVolume . bind ( this ) ) ; if ( voiceVolume != undefined ) { this . volume = voiceVolume ; } if ( isOpenVoice != undefined ) { this . muted = isOpenVoice ; } } public static bgVolume ( volume ) { this . volume = volume ; } param data public static play ( data ) { let res = data . res ; let nick = data . nick || this . DEFAULT_NICK ; let group = data . group || "bgm" ; let volume = data . volume == undefined ? 1 : data . volume ; let muted = data . muted == undefined ? false : data . muted ; let count = data . count == undefined ? - 1 : data . count ; let destroyAudio = ! ! data . destroyAudio ; let endCallback = data . endCallback ; return this . mBgmAduio . play ( { res , volume , muted , group , destroyAudio , count , endCallback , nick , } ) ; } param nick public static get ( nick ? ) { return this . mBgmAduio . get ( nick || this . DEFAULT_NICK ) ; } param nick public static destroy ( nick ? , destroyAudio ? ) { this . mBgmAduio . destroy ( nick || this . DEFAULT_NICK , destroyAudio ) ; } param nick public static destroyAll ( destroyAudio ? ) { this . mBgmAduio . destroyAll ( destroyAudio ) ; } }