/*
 * @Author: ls
 * @Date: 2022-05-15 18:22:18
 * @LastEditTime: 2022-06-14 18:59:07
 * @LastEditors: ls
 * @Description:
 * @FilePath: \ls_gramophone\assets\ls_gramophone\scene\ls_gramophone.ts
 */

// import { threadId } from _ls_gramophone_2'worker_threads';
import Item from './Item_ls_gramophone_2';
import { MyCocosSceneComponent } from '../script/MyCocosSceneComponent_ls_gramophone_2';
import { onHomeworkFinish } from '../script/util_ls_gramophone_2';
import pg from './pg_ls_gramophone_2';

const { ccclass, property } = cc._decorator;

@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
	@property(cc.Node)
	item: cc.Node = null;

	@property(cc.Node)
	down_item: cc.Node = null;

	@property(cc.Node)
	content: cc.Node = null;

	@property(cc.Node)
	tip: cc.Node = null;

	// @property(cc.Node)
	// pagContent: cc.Node = null;

	@property(cc.Node)
	btn_arrow: cc.Node = null;

	@property(cc.Node)
	btn_last: cc.Node = null;

	@property(cc.Node)
	mask: cc.Node = null;

	@property(cc.Node)
	record_start: cc.Node = null;

	@property(cc.Node)
	record_stop: cc.Node = null;

	@property(cc.Node)
	btn_audio_off: cc.Node = null;
	@property(cc.Node)
	btn_audio_on: cc.Node = null;

	// 录音中
	_recording = false;
	// 录音音频
	_records = [];
	// 倒计时
	_countdown = 30;

	_changStr = [];
	// 当前
	_curIndex = -1;

	_results = [];
	private guide = true;

	private isPlayBgAudio: boolean;
	private _curData = null;
	addPreloadImage() {
		// TODO 根据自己的配置预加载图片资源
		this._imageResList.push({ url: this.data.pageImage });
	}

	addPreloadAudio() {
		// TODO 根据自己的配置预加载音频资源
		this._audioResList.push({ url: this.data.questionTextAudio });
		this._audioResList.push({ url: this.data.pageAudio });

		for (let index = 0; index < this.data.questions.length; index++) {
			this._audioResList.push({ url: this.data.questions[index].audio });
		}
	}

	addPreloadAnima() { }

	onLoadEnd() {
		// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
		this.initData();
		this.initView();
		this.showTip();
	}

	initData() {
		this._recording = false;
		this._curData = null;
		this.roundIdx = 0;
		this.clickIdx = 0;
		this.guide = true;

		this._records.length = 0;
		this._changStr.length = 0;
		this._results.length = 0;
		this.data.questions.forEach((element, idx) => {
			this._records.push([]);
			this._results.push([]);
			this._changStr.push([]);
			element.options.forEach((op, id) => {
				op.id = id;
				this._records[idx].push(null);
				this._results[idx].push(null);
				this._changStr[idx].push(null);
			});
		});
		this.isPlayBgAudio = true;
	}
	private initDown() {
		let g_down = cc.find("g_down", this.node);
		let bg_tip1 = cc.find("bg_tip1", g_down);
		let bg_tip2 = cc.find("bg_tip2", g_down);
		bg_tip1.active = this.guide && this.roundIdx == 0;
		bg_tip2.active = this.guide && this.roundIdx == 0;
		g_down.active = true;
		this.showDownItem();
	}
	private initMiddle() {
		let g_middle = cc.find("g_middle", this.node);
		let content = cc.find("sc_down/view/content", g_middle);
		g_middle.opacity = 1;
		g_middle.active = true;
		this.initScrollView(content);
		setTimeout(() => {
			content.getComponent(cc.Layout).updateLayout();
			g_middle.active = false;
			g_middle.opacity = 255;
		}, 60);
	}
	private initScrollView(content) {
		content.removeAllChildren();
		let data = this.data.questions[this.roundIdx];
		for (let i = 0; i < data.options.length; i++) {
			let quest = data.options[i];
			let item = cc.instantiate(this.item);
			item.name = '' + i;
			item.parent = content;
			// item.x = -316;
			this.initItem(item, quest);
			if (this._changStr[this.roundIdx][i] != null) item.getComponent(Item).changStr = this._changStr[this.roundIdx][i];
			// const element = this.content.children[index];

		}
		content.getComponent(cc.Layout).updateLayout();
	}
	private initItem(item, quest) {
		item.getComponent(Item).init(quest.text);
		item.active = true;
		item.data = quest;
		// 播放当前句子
		item.off('click');
		item.on('click', () => {
			this.onItem(item, quest, quest.id);
		});

		item.getComponent(Item).recorded();

		let record = cc.find('btn_record', item);
		record.off('click');
		record.on('click', () => {
			if (this._recording) return;
			this.onItemRecord(item, quest, quest.id);
		});

		item.getComponent(Item).hideRecord();

		let myrecord = cc.find('btn_myrecord', item);
		let myrecord_play = cc.find('btn_myrecord_play', item);
		myrecord.off('click');
		myrecord_play.off('click');
		myrecord.on('click', () => {
			this.onMyRecord(item, quest.id);
		});
		myrecord_play.on('click', () => {
			this.onMyRecordPlay(item);
		});
	}
	private showDownItem() {
		let data = this.data.questions[this.roundIdx].options[this.clickIdx];
		this.initItem(this.down_item, data);
		let id = this.down_item.data.id;
		if (this._changStr[this.roundIdx][id] != null) this.down_item.getComponent(Item).changStr = this._changStr[this.roundIdx][id];
		this.resetText();
		this.resetRecord();
	}
	private clickIdx;
	private onItem(item, quest, idx) {
		this.clickIdx = idx;
		this.cleanLaba();
		this.resetText();
		this.resetRecord();
		this.stopQuestionAudio();
		// cc.audioEngine.stopAll();
		// play.active = false;
		// stop.active = true;

		item.getComponent(Item).playing();
		this.playAudioByUrl(quest.audio, () => {
			item.getComponent(Item).stop(this._records[this.roundIdx][idx] === null);
		});
	}
	private onItemRecord(item, quest, idx) {
		this.clickIdx = idx;
		this.cleanLaba();
		this.resetText();
		this.resetRecord();
		this.stopQuestionAudio();
		// cc.audioEngine.stopAll();
		// play.active = false;
		// stop.active = true;
		let g_down = cc.find("g_down", this.node);
		let bg_tip1 = cc.find("bg_tip1", g_down);
		let bg_tip2 = cc.find("bg_tip2", g_down);
		bg_tip1.active = false;
		bg_tip2.active = false;

		this.playLocalAudio('btn');
		item.getComponent(Item).recording();

		// 显示录音界面
		this.mask.active = true;
		this.record_start.active = true;
		this.record_stop.active = false;
		this._curData = quest;
		this._curIndex = idx;
	}
	private onMyRecordPlay(item) {
		this.cleanLaba();
		// cc.audioEngine.stopAll();
		this.stopQuestionAudio();
		item.getComponent(Item).stopRecord();
		item.getComponent(Item).stopAction();
	}

	private onMyRecord(item, idx) {
		this.cleanLaba();
		this.resetText();
		this.resetRecord();
		// cc.audioEngine.stopAll();
		this.stopQuestionAudio();
		item.getComponent(Item).playRecord();
		item.getComponent(Item).playAction();
		//
		if (this._records[this.roundIdx][idx] != null) {
			this.playAudioByUrl(this._records[this.roundIdx][idx], () => {
				item.getComponent(Item).stopRecord();
			}); // 播放音效
		}
	}
	private onUp() {
		let g_down = cc.find("g_down", this.node);
		let g_middle = cc.find("g_middle", this.node);
		this.guide = false;
		g_down.active = false;
		g_middle.active = true;
		let bg_tip1 = cc.find("bg_tip1", g_down);
		let bg_tip2 = cc.find("bg_tip2", g_down);
		bg_tip1.active = this.guide;
		bg_tip2.active = this.guide;
	}
	private onDown() {
		let g_down = cc.find("g_down", this.node);
		let g_middle = cc.find("g_middle", this.node);
		this.guide = false;
		g_down.active = true;
		g_down.opacity = 1;
		g_middle.active = false;
		setTimeout(() => {
			g_down.opacity = 255;
			// 	this.scroolTo();
		}, 30);

		this.showDownItem();
	}
	private getRecordIdx() {
		let g_down = cc.find("g_down", this.node);
		let g_middle = cc.find("g_middle", this.node);
		let idx = -1;
		if (g_down.active) {
			let data = this.down_item.data;
			idx = data.id;
		} else if (g_middle.active) {
			let content = cc.find("sc_down/view/content", g_middle);
			content.children.forEach((item, index) => {
				if (item.getComponent(Item).getRecording()) {
					idx = index;
				}
			})
		}
		return idx;
	}

	private stopQuestionAudio() {
		if (this.questionAudioId > -1) pg.audio.stopAudio(this.questionAudioId);
	}
	private intervalId;
	private questionAudioId = -1;
	private playLaba() {
		this.cleanLaba();
		this.resetText();
		let btn_play = cc.find("btn_play", this.node);
		let btn_laba1 = btn_play.getChildByName("btn_laba1");
		let btn_laba2 = btn_play.getChildByName("btn_laba2");
		btn_laba1.active = true;
		btn_laba2.active = true;
		if (this.questionAudioId > -1) pg.audio.stopAudio(this.questionAudioId);
		// cc.audioEngine.stopAllEffects();
		let count = 0;
		if (this.intervalId) clearInterval(this.intervalId);
		let stop = false;
		this.intervalId = setInterval(() => {
			count++;
			btn_laba1.active = count % 2 == 0;
			btn_laba2.active = count % 2 == 1;
			if (stop && count % 2 == 0) {
				btn_laba1.active = true;
				btn_laba2.active = true;
				clearInterval(this.intervalId);
			}
		}, 150)
		pg.audio.playAudioByUrl(this.data.questions[this.roundIdx].audio, (() => {
			stop = true;
			btn_laba1.active = true;
			btn_laba2.active = true;
		})).then((audioId: number) => {
			this.questionAudioId = audioId;
		})
	}
	private cleanLaba() {
		if (this.intervalId) clearInterval(this.intervalId);
		let btn_play = cc.find("btn_play", this.node);
		let btn_laba1 = btn_play.getChildByName("btn_laba1");
		let btn_laba2 = btn_play.getChildByName("btn_laba2");
		btn_laba1.active = true;
		btn_laba2.active = true;
	}
	initView() {
		this.initDown();
		this.initMiddle();
		let self = this;
		const bgNode = cc.find('Canvas/bg');
		bgNode.scale = this._mapScaleMax;

		cc.find('Canvas/bg_title/label').getComponent(cc.Label).string = this.data.title;

		let play = cc.find('Canvas/btn_play');
		let stop = cc.find('Canvas/btn_stop');
		// play.active = false;
		// stop.active = true;
		play.off('click');
		stop.off('click');
		play.on('click', () => {
			this.playLaba();
		});
		// 录音界面
		let mask = cc.find('Canvas/mask');
		mask.active = false;

		let icon_record = cc.find('Canvas/mask/icon_record');
		// icon_record.getComponent(dragonBones.ArmatureDisplay).timeScale = 0;

		let record_start = cc.find('Canvas/btn_record_start');
		let record_stop = cc.find('Canvas/btn_record_stop');
		let countdown = cc.find('Canvas/bg_countdown');
		record_start.active = false;
		record_stop.active = false;
		countdown.active = false;
		record_start.off('click');
		record_stop.off('click');
		record_start.on('click', () => {
			this.playLocalAudio('btn');
			this.stopBgAudio();
			mask.active = true;
			// icon_record.getComponent(dragonBones.ArmatureDisplay).timeScale = 1;

			record_start.active = false;
			record_stop.active = true;
			countdown.active = true;

			let cd = 10;
			if (this._curData) {
				cd = this._curData.duration || 10;
			}
			this.unschedule(this.onCountdown);
			this._countdown = Number(cd) + 1;
			this.onCountdown();
			this.schedule(this.onCountdown, 1);

			this._recording = true;

			let idx = this.getRecordIdx(); // 获取当前录制下标
			// for (let index = 0; index < this.content.childrenCount; index++) {
			// 	const element = this.content.children[index];
			// 	// 正在录制中
			// 	if (element.getComponent(Item).getRecording()) {
			// 		idx = index;
			// 		break;
			// 	}
			// }

			this.log('idx:' + idx);
			let text = self.data.questions[self.roundIdx].options[idx].text;
			this.log("text: " + text);
			if (window['courseware']) {
				if (idx !== -1) {
					this.log("1");
					window['courseware'].startTest(text);
				}
			}
		});
		record_stop.on('click', () => {
			this.playLocalAudio('btn');

			mask.active = false;
			// icon_record.getComponent(dragonBones.ArmatureDisplay).timeScale = 0;

			record_start.active = false;
			record_stop.active = false;
			countdown.active = false;

			this.unschedule(this.onCountdown);
			this._curIndex = -1;
			this._curData = null

			this._recording = false;


			let idx = this.getRecordIdx(); // 获取当前录制下标
			// for (let index = 0; index < this.content.childrenCount; index++) {
			// 	const element = this.content.children[index];
			// 	// 正在录制中
			// 	if (element.getComponent(Item).getRecording()) {
			// 		idx = index;
			// 		break;
			// 	}
			// }


			this.log('idx:' + idx);

			if (window['courseware']) {
				this.playBgAudio();
				window['courseware'].stopTest((res) => {
					this.log('--------录音返回结果 stopTest ------------');
					this.log('res' + res);
					res = JSON.parse(res);
					this.log('json res.result' + JSON.stringify(res.result));
					this.log('json res.result.sentences' + JSON.stringify(res.result.sentences));

					if (idx !== -1) {
						// let it = this.content.children[idx].getComponent(Item);
						let g_middle = cc.find("g_middle", this.node);
						let middle_content = cc.find("sc_down/view/content", g_middle);
						this.recordDownEnd(res, idx);
						this.recordEnd(middle_content, res, idx);
					}

					if (res && res.audioUrl) {
						if (idx !== -1) {
							this._records[this.roundIdx][idx] = res.audioUrl;
							// this._records[idx] = res.audioUrl;
							this.log(`${idx} ===> ${res.audioUrl}`);
							this.resetRecord();

							// this.scheduleOnce(() => {});
						}
					}

					this._results[this.roundIdx][idx] = res;
					for (const iterator of this._results) {
						for (const op of iterator) {
							if (op === null) {
								return;
							}
						}
					}
					let send: any = {};
					send.stone = 10;
					send.details = this._results;
					onHomeworkFinish(send);
				});
			} else {
				this.playBgAudio();
				if (idx !== -1) {
					let g_middle = cc.find("g_middle", this.node);

					let res = { "audioUrl": "https://staging-teach.cdn.ireadabc.com/bea0ba87bcf8bc09815f34b4790ffac9.mp3", "eof": 1, "file": "/storage/emulated/0/Android/data/com.example.oxford/cache/shengtong/gradeVoice.mp3", "result": { "duration": "2.670", "fluency": 86, "integrity": 50, "kernel_version": "3.7.1", "overall": 28, "pronunciation": 28, "resource_version": "2.3.11", "rhythm": 28, "sentences": [{ "beginIndex": 0, "details": [{ "charType": 0, "end": 0, "overall": 56, "prominence": 0, "start": 0, "word": "Good" }, { "charType": 0, "end": 0, "overall": 0, "prominence": 0, "start": 0, "word": "morning" }], "end": 0, "endIndex": 0, "overall": 28, "sentence": "Good morning", "start": 0 }], "speed": 28 }, "tokenId": "62d7a2343327934258000009" }

					let middle_content = cc.find("sc_down/view/content", g_middle);
					this.recordDownEnd(res, idx);
					this.recordEnd(middle_content, res, idx);
					this.down_item.getComponent(Item).recorded();
					middle_content.children[idx].getComponent(Item).recorded();
				}
				// 模拟测试
				this._records[this.roundIdx][idx] = 'http://staging-teach.cdn.ireadabc.com/92ddbc65e9af775f7a8450a5bef1a732.mp3';
			}
			this.resetRecord();
		});
		this.btn_arrow.on(cc.Node.EventType.TOUCH_END, this.onArrow, this);
		this.btn_last.on(cc.Node.EventType.TOUCH_END, this.onLast, this);
		this.btn_audio_off.on(cc.Node.EventType.TOUCH_END, this.onAudioOff, this);
		this.btn_audio_on.on(cc.Node.EventType.TOUCH_END, this.onAudioOn, this);
		this.setPagBg();
		this.refreshArrow();
		this.arrowAction();

		if (this.data.bgAudio && this.data.bgAudio != "") {
			this.btn_audio_on.active = true;
		}
	}
	private onAudioOn() {
		this.btn_audio_off.active = true;
		this.btn_audio_on.active = false;
		this.isPlayBgAudio = false;
		this.stopBgAudio();
	}
	private onAudioOff() {
		this.btn_audio_on.active = true;
		this.btn_audio_off.active = false;
		this.isPlayBgAudio = true;
		this.playBgAudio();
	}
	private playBgAudio() {
		if (!this.isPlayBgAudio) return;
		cc.audioEngine.resumeMusic();
	}
	private stopBgAudio() {
		cc.audioEngine.pauseMusic();
	}
	private recordEnd(content, res, idx) {
		let it = content.children[idx].getComponent(Item);
		it.recorded();

		let arr = [];
		for (let index = 0; index < res.result.sentences.length; index++) {
			let e = res.result.sentences[index];
			arr = arr.concat(e.details);
		}

		it.cleanText();
		let arrOne = [];
		for (let index = 0; index < arr.length; index++) {
			let e = arr[index];

			arrOne.push({ key: e.word, value: 1 });

			let result = {};
			arrOne.forEach((item) => {
				if (result[item.key]) {
					result[item.key] += item.value;
				} else {
					result[item.key] = item.value;
				}
			});

			for (let k in result) {
				if (k === e.word) {
					let w = index == 0 ? e.word : " " + e.word;
					if (e.overall < 40) {
						it.changColor(w, true);
					} else {
						it.changColor(w, false);
					}
				}
			}
		}
		this._changStr[this.roundIdx][idx] = it.getComponent(Item).changStr;
	}
	private recordDownEnd(res, idx) {
		let it = this.down_item.getComponent(Item);
		if (idx != this.down_item.data.id) return;
		it.recorded();

		let arr = [];
		for (let index = 0; index < res.result.sentences.length; index++) {
			let e = res.result.sentences[index];
			arr = arr.concat(e.details);
		}

		it.cleanText();
		let arrOne = [];
		for (let index = 0; index < arr.length; index++) {
			let e = arr[index];

			arrOne.push({ key: e.word, value: 1 });

			let result = {};
			arrOne.forEach((item) => {
				if (result[item.key]) {
					result[item.key] += item.value;
				} else {
					result[item.key] = item.value;
				}
			});

			for (let k in result) {
				if (k === e.word) {
					let w = index == 0 ? e.word : " " + e.word;
					if (e.overall < 40) {
						it.changColor(w, true);
					} else {
						it.changColor(w, false);
					}
				}
			}
		}
		this._changStr[this.roundIdx][idx] = it.getComponent(Item).changStr;
	}
	private roundIdx;
	private setPagBg() {
		let play = cc.find('Canvas/btn_play');
		// let stop = cc.find('Canvas/btn_stop');
		play.active = true;
		// stop.active = true;
		if (this.questionAudioId > -1) pg.audio.stopAudio(this.questionAudioId);
		this.resetText();
		this.resetRecord();
		let data = this.data.questions[this.roundIdx].pageImage;
		this.getSpriteFrimeByUrl(data, (sp) => {//+ '?x-oss-process=image/resize,m_fill,h_520,w_560'
			// this.getSpriteFrimeByUrl(this.data.pageImage, (sp) => {
			cc.find('Canvas/bg_img/img').getComponent(cc.Sprite).spriteFrame = sp;
			cc.find('Canvas/bg_img/img').width = 1209;
			cc.find('Canvas/bg_img/img').height = 649;
			cc.find('Canvas/bg_img/img').scale = 1;// Math.max(520 / cc.find('Canvas/bg_img/img').width, 560 / cc.find('Canvas/bg_img/img').height);
		});

	}
	private refreshArrow() {
		this.btn_last.active = this.roundIdx > 0;
		this.btn_arrow.active = this.roundIdx < this.data.questions.length - 1;
	}
	private arrowTouch = false;
	private onArrow() {
		if (this.arrowTouch) return;
		// this.arrowTouch = true;
		this.roundIdx++;
		this.clickIdx = 0;
		// let pag = cc.find("PageView", this.node);
		// pag.getComponent(cc.PageView).enabled = true;
		// pag.getComponent(cc.PageView).scrollToPage(this.roundIdx, 0.1);
		this.resetLaba();
		this.setPagBg();
		this.initDown();
		this.initMiddle();
		this.refreshArrow();
		this.resetText();
		this.resetRecord();
	}
	private onLast() {
		if (this.arrowTouch) return;
		// this.arrowTouch = true;
		this.roundIdx--;
		this.clickIdx = 0;
		// let pag = cc.find("PageView", this.node);
		// let len = pag.getComponent(cc.PageView).getPages().length;
		// if (len <= 1) return;
		// pag.getComponent(cc.PageView).enabled = true;
		// pag.getComponent(cc.PageView).scrollToPage(this.roundIdx, 0.1);
		this.resetLaba();
		this.setPagBg();
		this.initDown();
		this.initMiddle();
		this.refreshArrow();
		this.resetText();
		this.resetRecord();
	}
	private resetLaba() {
		if (this.intervalId) clearInterval(this.intervalId);
		let btn_play = cc.find("btn_play", this.node);
		let btn_laba1 = btn_play.getChildByName("btn_laba1");
		let btn_laba2 = btn_play.getChildByName("btn_laba2");
		btn_laba1.active = true;
		btn_laba2.active = true;
	}

	private arrowAction() {
		let icon_arrow = cc.find("g_down/btn_up/icon_arrow", this.node);
		icon_arrow.scale
		cc.tween(icon_arrow).repeatForever(
			cc.tween().to(0.3, { scale: 1.3 })
				.to(0.3, { scale: 0.9 }).to(0.3, { scale: 1.3 })
				.to(0.3, { scale: 0.9 }).to(0.3, { scale: 1 }).delay(0.5)
		).start();
	}

	/**
	 * 重置文字
	 */
	resetText() {
		this.down_item.getComponent(Item).stop(this._records[this.roundIdx][this.down_item.data.id] === null);
		let middle = cc.find("g_middle/sc_down/view/content", this.node);
		middle.children.forEach((item, index) => {
			item.getComponent(Item).stop(this._records[this.roundIdx][index] === null);
		})
	}

	/**
	 * 重置录制音频
	 */
	resetRecord() {
		let data = this.down_item.data;
		this.down_item.getComponent(Item).hideRecord();
		for (let i = 0; i < this._records[this.roundIdx].length; i++) {
			let item = this._records[this.roundIdx][i];
			if (item && data.id == i) this.down_item.getComponent(Item).stopRecord();
		}
		let middle = cc.find("g_middle/sc_down/view/content", this.node);
		for (let index = 0; index < middle.childrenCount; index++) {
			const element = middle.children[index];
			if (this._records[this.roundIdx][index] === null) {
				element.getComponent(Item).hideRecord();
			} else {
				console.log(`===> ${index}`);
				element.getComponent(Item).stopRecord();
			}
		}
	}

	/**
	 * 显示提示
	 * @param first
	 */
	showTip(first: boolean = true) {
		this.tip.active = true;

		cc.find('start', this.tip).active = first;
		cc.find('restart', this.tip).active = !first;

		// 提示
		let tip = cc.find('bg', this.tip);
		tip.off('click');
		tip.on('click', () => {
			cc.audioEngine.stopAll();
			this.playAudioByUrl(this.data.questionTextAudio, () => { }); // 播放提示音效
		});
		// 提示内容
		let tip_label = cc.find('label', this.tip).getComponent(cc.Label);
		tip_label.string = this.data.questionText;
		this.playAudioByUrl(this.data.questionTextAudio, () => { }); // 播放提示音效
	}

	/**
	 * 隐藏提示
	 */
	hideTip() {
		this.tip.active = false;
	}

	/**
	 * 倒计时回调
	 */
	onCountdown() {
		this._countdown--;
		if (this._countdown <= 0) {
			let record_stop = cc.find('Canvas/btn_record_stop');

			record_stop.emit('click');
			this.unschedule(this.onCountdown);
		} else {
			let bg_countdown_label = cc.find('Canvas/bg_countdown/label');
			bg_countdown_label.getComponent(cc.Label).string = this._countdown + '';
			if (this._countdown > 5) {
				bg_countdown_label.color = cc.color(83, 102, 138);
				bg_countdown_label.getComponent(cc.Label).fontSize = 50;
				bg_countdown_label.getComponent(cc.LabelOutline).enabled = false;
			} else {
				bg_countdown_label.color = cc.color(255, 132, 132);
				bg_countdown_label.getComponent(cc.Label).fontSize = 64;
				bg_countdown_label.getComponent(cc.LabelOutline).enabled = true;
			}
		}
	}

	onCallBack(event: cc.Event.EventTouch, str: string) {
		if (str === 'start' || str === 'restart') {
			cc.audioEngine.stopAll();
			this.playLocalAudio('btn');
			pg.audio.playBgAudioByUrl(this.data.bgAudio);
			this.hideTip();
		} else if (str === 'record_start') {
		} else if (str === 'record_stop') {
		}
	}

	playLocalAudio(audioName) {
		const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
		return new Promise((resolve, reject) => {
			const id = cc.audioEngine.playEffect(audio.clip, false);
			cc.audioEngine.setFinishCallback(id, () => {
				resolve(id);
			});
		});
	}
}

