import AudioComponent from "../../framework/base/AudioComponent" ; import { BUNDLE_TYPE , BUNDLE_RESOURCES } from "../../framework/base/Defines" ; import { Manager } from "../manager/Manager" ; description const { ccclass , property , menu } = cc . _decorator ; @ ccclass @ menu ( "common/component/GlobalAudio" ) export default class GlobalAudio extends AudioComponent { public playMusic ( url , bundle , loop = true ) { let me = this ; return new Promise < { url : string ; isSuccess : boolean ; } > ( ( resolve ) => { this . audioData . curMusicUrl = url ; if ( this . audioData . isMusicOn ) { Manager . cacheManager . getCacheByAsync ( url , cc . AudioClip , BUNDLE_RESOURCES ) . then ( ( data ) => { if ( data ) { me . stopMusic ( ) ; cc . audioEngine . playMusic ( data , loop ) ; resolve ( { url : url , isSuccess : true } ) ; } else { resolve ( { url : url , isSuccess : false } ) ; } } ) ; } } ) ; } public playEffect ( url , bundle , loop = false ) { return new Promise < number > ( ( resolve ) => { if ( this . audioData . isEffectOn ) { Manager . cacheManager . getCacheByAsync ( url , cc . AudioClip , BUNDLE_RESOURCES ) . then ( ( data ) => { if ( data ) { this . audioData . curEffectId = cc . audioEngine . playEffect ( data , loop ) ; resolve ( this . audioData . curEffectId ) ; } else { resolve ( this . audioData . curEffectId ) ; } } ) ; } else { this . audioData . curEffectId = - 1 ; resolve ( - 1 ) ; } } ) ; } onLoad ( ) { this . effectVolume = this . audioData . effectVolume ; this . musicVolume = this . audioData . musicVolume ; } }