逻辑完善
This commit is contained in:
@@ -301,29 +301,55 @@ class AudioManager {
|
||||
}
|
||||
|
||||
// 播放指定音频或音频数组(数组则按顺序连续播放)
|
||||
play(input) {
|
||||
// 再次调用 play:打断前面所有声音与队列
|
||||
play(input, interrupt = true) {
|
||||
// 统一规范化为队列
|
||||
let queue = [];
|
||||
if (Array.isArray(input)) {
|
||||
queue = input.filter((k) => !!audioFils[k]);
|
||||
} else if (typeof input === "string") {
|
||||
queue = !!audioFils[input] ? [input] : [];
|
||||
} else {
|
||||
debugLog("play 参数类型无效,仅支持字符串或字符串数组");
|
||||
return;
|
||||
}
|
||||
|
||||
if (queue.length === 0) {
|
||||
debugLog("连续播放队列为空或无效");
|
||||
return;
|
||||
}
|
||||
|
||||
if (interrupt) {
|
||||
// 立即打断并启动新的播放序列
|
||||
this.stopAll();
|
||||
this.isSequenceRunning = false;
|
||||
this.sequenceQueue = [];
|
||||
this.sequenceIndex = 0;
|
||||
|
||||
if (Array.isArray(input)) {
|
||||
// 过滤可播放的 key
|
||||
const queue = input.filter((k) => !!audioFils[k]);
|
||||
if (queue.length === 0) {
|
||||
debugLog("连续播放队列为空或无效");
|
||||
return;
|
||||
}
|
||||
this.sequenceQueue = queue;
|
||||
this.sequenceIndex = 0;
|
||||
this.isSequenceRunning = true;
|
||||
// 开始播放队列的第一个
|
||||
this._playSingle(queue[0], false);
|
||||
} else if (typeof input === "string") {
|
||||
this._playSingle(input, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 不打断当前播放:把新的队列加入到序列中,等待当前播放结束后衔接
|
||||
if (this.currentPlayingKey) {
|
||||
if (this.isSequenceRunning) {
|
||||
// 已有序列在跑:直接追加
|
||||
this.sequenceQueue = this.sequenceQueue.concat(queue);
|
||||
} else {
|
||||
debugLog("play 参数类型无效,仅支持字符串或字符串数组");
|
||||
// 没有序列但当前有正在播放的:以当前为序列的起点
|
||||
this.isSequenceRunning = true;
|
||||
this.sequenceQueue = [this.currentPlayingKey].concat(queue);
|
||||
this.sequenceIndex = 0;
|
||||
// 不触发 _playSingle,等待当前音频自然结束后由 onAudioEnded 接管
|
||||
}
|
||||
} else {
|
||||
// 当前没有播放:直接启动新的序列
|
||||
this.sequenceQueue = queue;
|
||||
this.sequenceIndex = 0;
|
||||
this.isSequenceRunning = true;
|
||||
this._playSingle(queue[0], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,12 +172,12 @@ async function onReceiveMessage(messages = []) {
|
||||
wait.value = msg.wait;
|
||||
if (msg.wait === 20) {
|
||||
halfTime.value = true;
|
||||
audioManager.play("中场休息");
|
||||
audioManager.play("中场休息", false);
|
||||
}
|
||||
if (msg.wait === 0) {
|
||||
halfTime.value = false;
|
||||
}
|
||||
}, 500);
|
||||
}, 200);
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
audioManager.play("比赛结束");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||
import { onShow } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import ShootProgress from "@/components/ShootProgress.vue";
|
||||
import BowTarget from "@/components/BowTarget.vue";
|
||||
@@ -55,9 +56,9 @@ async function onReceiveMessage(messages = []) {
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (scores.value.length === 3) audioManager.play("第二轮");
|
||||
if (scores.value.length === 9) audioManager.play("第四轮");
|
||||
}, 500);
|
||||
if (scores.value.length === 3) audioManager.play("第二轮", false);
|
||||
if (scores.value.length === 9) audioManager.play("第四轮", false);
|
||||
}, 200);
|
||||
} else if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
|
||||
if (practiseId.value && practiseId.value === msg.practice.id) {
|
||||
setTimeout(() => {
|
||||
@@ -70,12 +71,15 @@ async function onReceiveMessage(messages = []) {
|
||||
}, 1500);
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
|
||||
if (msg.wait === 20) {
|
||||
uni.$emit("update-ramain", 0);
|
||||
wait.value = msg.wait;
|
||||
if (msg.wait === 20) uni.$emit("update-ramain", 0);
|
||||
}
|
||||
if (msg.wait === 0) {
|
||||
let count = 60;
|
||||
wait.value = msg.wait;
|
||||
uni.$emit("update-ramain", count);
|
||||
if (scores.value.length === 6) audioManager.play("第三轮");
|
||||
if (scores.value.length === 6) audioManager.play("第三轮", false);
|
||||
setInterval(() => {
|
||||
count -= 1;
|
||||
if (count === 30) {
|
||||
|
||||
Reference in New Issue
Block a user