class AudioManager {
    static audioManager:AudioManager = null;
    static get instance()
    {
        if(!this.audioManager)
           return  this.audioManager = new AudioManager();
        else
          return this.audioManager;
    }
    //背景音乐
    private bg_sound:egret.Sound;
    //点击按钮的声音
    private click_sound:egret.Sound;
    //TODO 一些更多特效的声音根据需求增加
    private _isBgMusic:boolean;
    private _isEffect:boolean;
    //音轨
    private soundChannel:egret.SoundChannel;
    public constructor() {
        this.bg_sound = new egret.Sound();
        this.bg_sound.load(“resource/assets/data/sound/Audio_Main.mp3”);
        this.bg_sound.addEventListener(egret.Event.COMPLETE,()=>{
            this.playBgMusic();
        },this);
        this.click_sound = new egret.Sound();
        this.click_sound.load(“resource/assets/data/sound/click1.mp3”);
    }
    //是否播放音乐
    public get isBgMusic():boolean
    {
        var _m = egret.localStorage.getItem(“isMusic”);
        if(_m == null || _m == “”)
            return  true;
        else
            return  _m == “1”;
    }
    //设置播放音乐
    public set isBgMusic(val)
    {
        egret.localStorage.setItem(“isMusic”, val ? “1”:”0″);
    }
    //是否播放音效
    public get isEffect():boolean
    {
        var _m = egret.localStorage.getItem(“isEffect”);
        if(_m == null || _m == “”)
            return  true;
        else
            return  _m == “1”;
    }
    //设置播放音效
    public set isEffect(val)
    {
        egret.localStorage.setItem(“isEffect”, val ? “1”:”0″);
    }
    //播放背景音乐
    public playBgMusic()
    {
        if(this.bg_sound)
        {
            if(this.isBgMusic)
                this.bg_sound.play(0,0);
            else
                this.soundChannel.stop();
        }
    }
    //播放点击按钮音效
    public playClick()
    {
        if(this.click_sound && this.isEffect)
            this.click_sound.play(0,1);
    }
}