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