import { AudioComponent , AudioManager , EventManager , HTMLAudio , UUIDUtils } from "../../framework" ; import { Audio } from "./Audio" ; import { AudioInterface } from "./interface/AudioInterface" ; /**
 * 音效
 */ export class Sound { private static mSoundAduio : Audio = new Audio ( ) ; private static isInit : boolean = false ; public static set volume ( volume ) { this . mSoundAduio . volume = volume ; } public static get volume ( ) : number { return this . mSoundAduio . volume ; } public static set muted ( muted ) { this . mSoundAduio . muted = muted ; } public static get muted ( ) : boolean { return this . mSoundAduio . muted ; } public static set mutedOffset ( mutedOffset ) { this . mSoundAduio . mutedOffset = mutedOffset ; } public static get mutedOffset ( ) : boolean { return this . mSoundAduio . mutedOffset ; } public static get audioMap ( ) : Map < string , AudioInterface > { return this . mSoundAduio . mAudioMap ; } public static init ( voiceVolume ? , isOpenVoice ? ) { if ( this . isInit ) { return ; } this . isInit = true ; EventManager . on ( "音效音量改变" , this . soundVolume . bind ( this ) ) ; if ( voiceVolume != undefined ) { this . volume = voiceVolume ; } if ( isOpenVoice != undefined ) { this . muted = isOpenVoice ; } } public static soundVolume ( volume ) { this . volume = volume ; } param data public static play ( data ) { if ( AudioManager . isGlobalPause || AudioManager . isOffsetPause ) { return "" ; } let res = data . res ; let nick = data . nick || UUIDUtils . getUUID ( ) ; let group = data . group || "sound" ; 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 . mSoundAduio . play ( { res , volume , group , muted , destroyAudio , count , endCallback , nick , } ) ; } param nick public static get ( nick ) { return this . mSoundAduio . get ( nick ) ; } param nick public static destroy ( nick , destroyAudio ? ) { this . mSoundAduio . destroy ( nick , destroyAudio ) ; } param nick public static destroyAll ( destroyAudio ? ) { this . mSoundAduio . destroyAll ( destroyAudio ) ; } }