音频播放bug修复
This commit is contained in:
@@ -4,127 +4,140 @@ import { CommonConfig } from "../Config/CommonConfig";
|
||||
import AudioManager from "./AudioManager";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
@ccclass('PlayerDataManager')
|
||||
@ccclass("PlayerDataManager")
|
||||
export default class PlayerDataManager {
|
||||
private static _I: PlayerDataManager = null;
|
||||
public static get I(): PlayerDataManager {
|
||||
if (!PlayerDataManager._I) {
|
||||
PlayerDataManager._I = new PlayerDataManager();
|
||||
PlayerDataManager._I.init()
|
||||
}
|
||||
return PlayerDataManager._I;
|
||||
private static _I: PlayerDataManager = null;
|
||||
public static get I(): PlayerDataManager {
|
||||
if (!PlayerDataManager._I) {
|
||||
PlayerDataManager._I = new PlayerDataManager();
|
||||
PlayerDataManager._I.init();
|
||||
}
|
||||
return PlayerDataManager._I;
|
||||
}
|
||||
|
||||
private isShakeOn: boolean = true; //震动
|
||||
private isMusicOn: boolean = true; //音乐
|
||||
private isSoundOn: boolean = true; //音效
|
||||
private guideMainFinished: boolean = false; //主界面引导是否完成
|
||||
private guideTalkFinished: boolean = false; //聊天界面引导是否完成
|
||||
private isShakeOn: boolean = true; //震动
|
||||
private isMusicOn: boolean = true; //音乐
|
||||
private isSoundOn: boolean = true; //音效
|
||||
private guideMainFinished: boolean = false; //主界面引导是否完成
|
||||
private guideTalkFinished: boolean = false; //聊天界面引导是否完成
|
||||
|
||||
public get IsShakeOn(): boolean {
|
||||
return this.isShakeOn;
|
||||
}
|
||||
public get IsMusicOn(): boolean {
|
||||
return this.isMusicOn;
|
||||
}
|
||||
public get IsSoundOn(): boolean {
|
||||
return this.isSoundOn;
|
||||
}
|
||||
public get GuideMainFinished(): boolean {
|
||||
return this.guideMainFinished;
|
||||
}
|
||||
public get GuideTalkFinished(): boolean {
|
||||
return this.guideTalkFinished;
|
||||
}
|
||||
|
||||
public get IsShakeOn() : boolean {return this.isShakeOn;}
|
||||
public get IsMusicOn() : boolean {return this.isMusicOn;}
|
||||
public get IsSoundOn() : boolean {return this.isSoundOn;}
|
||||
public get GuideMainFinished() : boolean {return this.guideMainFinished;}
|
||||
public get GuideTalkFinished() : boolean {return this.guideTalkFinished;}
|
||||
private init() {
|
||||
this.InitPlayerData();
|
||||
}
|
||||
public initEmpty() {}
|
||||
|
||||
private InitPlayerData() {
|
||||
// this.isShakeOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SHAKEON, true)
|
||||
this.isMusicOn = PlayerDataManager.getForKey(
|
||||
CommonConfig.StorageConfig.SETTING_MUSIC,
|
||||
true
|
||||
);
|
||||
this.isSoundOn = PlayerDataManager.getForKey(
|
||||
CommonConfig.StorageConfig.SETTING_SOUND,
|
||||
true
|
||||
);
|
||||
this.guideMainFinished = PlayerDataManager.getForKey(
|
||||
CommonConfig.StorageConfig.GUIDE_MAIN,
|
||||
false
|
||||
);
|
||||
this.guideTalkFinished = PlayerDataManager.getForKey(
|
||||
CommonConfig.StorageConfig.GUIDE_TALK,
|
||||
false
|
||||
);
|
||||
logger.log(
|
||||
"InitPlayerData",
|
||||
`music=${this.isMusicOn}, sound=${this.isSoundOn}, guideMain=${this.guideMainFinished}, guideTalk=${this.guideTalkFinished}`
|
||||
);
|
||||
}
|
||||
|
||||
private init(){
|
||||
this.InitPlayerData();
|
||||
}
|
||||
public initEmpty(){
|
||||
|
||||
public SetMusicOn(bo: boolean) {
|
||||
if (this.isMusicOn == bo) return;
|
||||
this.isMusicOn = bo;
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_MUSIC, bo);
|
||||
if (bo) {
|
||||
AudioManager.I.ReplayMusic();
|
||||
} else AudioManager.I.StopMusic();
|
||||
}
|
||||
|
||||
public SetSoundOn(bo: boolean) {
|
||||
if (this.isSoundOn == bo) return;
|
||||
this.isSoundOn = bo;
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_SOUND, bo);
|
||||
}
|
||||
|
||||
/**主界面引导完成*/
|
||||
public SetGuideMainFinish(bo: boolean) {
|
||||
if (this.guideMainFinished == bo) return;
|
||||
this.guideMainFinished = bo;
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_MAIN, bo);
|
||||
}
|
||||
/**聊天界面引导完成*/
|
||||
public SetGuideTalkFinish(bo: boolean) {
|
||||
if (this.guideTalkFinished == bo) return;
|
||||
this.guideTalkFinished = bo;
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_TALK, bo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型内部处理,外层部分类型 isBindingId //标识位数据需要绑定 playerid的时候,默认值为 true,若是传 false,则不进入绑定
|
||||
* */
|
||||
static setForKey(key: number | string, data) {
|
||||
if (!key || void 0 === data) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
key = key + "";
|
||||
sys.localStorage.setItem(key, JSON.stringify(data));
|
||||
}
|
||||
|
||||
|
||||
private InitPlayerData() {
|
||||
// this.isShakeOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SHAKEON, true)
|
||||
this.isMusicOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_MUSIC, true)
|
||||
this.isSoundOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SOUND, true)
|
||||
this.guideMainFinished = PlayerDataManager.getForKey(CommonConfig.StorageConfig.GUIDE_MAIN, false)
|
||||
this.guideTalkFinished = PlayerDataManager.getForKey(CommonConfig.StorageConfig.GUIDE_TALK, false)
|
||||
logger.log("InitPlayerData", `music=${this.isMusicOn}, sound=${this.isSoundOn}, guideMain=${this.guideMainFinished}, guideTalk=${this.guideTalkFinished}`)
|
||||
static getForKey(key: number | string, defaultVal): any {
|
||||
if (!key) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public SetMusicOn(bo: boolean) {
|
||||
if (this.isMusicOn == bo)
|
||||
return
|
||||
this.isMusicOn = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_MUSIC, bo)
|
||||
if (bo)
|
||||
AudioManager.I.ReplayMusic()
|
||||
else
|
||||
AudioManager.I.StopMusic()
|
||||
key = key + "";
|
||||
let jsonObj;
|
||||
try {
|
||||
let str = sys.localStorage.getItem(key);
|
||||
try {
|
||||
jsonObj = JSON.parse(str);
|
||||
} catch (error) {
|
||||
jsonObj = str;
|
||||
}
|
||||
} catch (error) {
|
||||
Utils.Log(`getForKey--->>>解析${key}的值的时候报错`);
|
||||
}
|
||||
if (jsonObj == null) {
|
||||
jsonObj = defaultVal;
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
public SetSoundOn(bo: boolean) {
|
||||
if (this.isSoundOn == bo)
|
||||
return
|
||||
this.isSoundOn = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_SOUND, bo)
|
||||
}
|
||||
static removeForKey(key: number | string): void {
|
||||
key = key + "";
|
||||
sys.localStorage.setItem(key, "");
|
||||
}
|
||||
|
||||
/**主界面引导完成*/
|
||||
public SetGuideMainFinish(bo: boolean) {
|
||||
if (this.guideMainFinished == bo)
|
||||
return
|
||||
this.guideMainFinished = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_MAIN, bo)
|
||||
}
|
||||
/**聊天界面引导完成*/
|
||||
public SetGuideTalkFinish(bo: boolean) {
|
||||
if (this.guideTalkFinished == bo)
|
||||
return
|
||||
this.guideTalkFinished = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_TALK, bo)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 类型内部处理,外层部分类型 isBindingId //标识位数据需要绑定 playerid的时候,默认值为 true,若是传 false,则不进入绑定
|
||||
* */
|
||||
static setForKey(key: number | string, data) {
|
||||
if (!key || void (0) === data) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
key = key + "";
|
||||
sys.localStorage.setItem(key, JSON.stringify(data));
|
||||
}
|
||||
|
||||
static getForKey(key: number | string, defaultVal): any {
|
||||
if (!key) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
key = key + "";
|
||||
let jsonObj;
|
||||
try {
|
||||
let str = sys.localStorage.getItem(key);
|
||||
try {
|
||||
jsonObj = JSON.parse(str);
|
||||
} catch (error) {
|
||||
jsonObj = str;
|
||||
}
|
||||
} catch (error) {
|
||||
Utils.Log(`getForKey--->>>解析${key}的值的时候报错`);
|
||||
}
|
||||
if (jsonObj == null){
|
||||
jsonObj = defaultVal;
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
static removeForKey(key: number | string): void {
|
||||
key = key + "";
|
||||
sys.localStorage.setItem(key, "");
|
||||
}
|
||||
|
||||
/**清档 */
|
||||
static clearAll(): void {
|
||||
sys.localStorage.clear();
|
||||
}
|
||||
}
|
||||
/**清档 */
|
||||
static clearAll(): void {
|
||||
sys.localStorage.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user