fix:修复语音,射箭数字,第一轮提前报靶问题
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
export const AUDIO_INTERRUPTION_BEGIN_EVENT = "audio-interruption-begin";
|
||||||
|
export const AUDIO_INTERRUPTION_END_EVENT = "audio-interruption-end";
|
||||||
|
|
||||||
export const audioFils = {
|
export const audioFils = {
|
||||||
tententen: "https://static.shelingxingqiu.com/shootmini/static/audio/tententen.mp3",
|
tententen: "https://static.shelingxingqiu.com/shootmini/static/audio/tententen.mp3",
|
||||||
点击按钮: "https://static.shelingxingqiu.com/shootmini/static/audio/%E7%82%B9%E5%87%BB%E6%8C%89%E9%92%AE.mp3",
|
点击按钮: "https://static.shelingxingqiu.com/shootmini/static/audio/%E7%82%B9%E5%87%BB%E6%8C%89%E9%92%AE.mp3",
|
||||||
@@ -97,7 +100,7 @@ function debugLog(...args) {
|
|||||||
const envVersion = accountInfo.miniProgram.envVersion;
|
const envVersion = accountInfo.miniProgram.envVersion;
|
||||||
|
|
||||||
// 只在体验版打印日志,正式版(release)和开发版(develop)不打印
|
// 只在体验版打印日志,正式版(release)和开发版(develop)不打印
|
||||||
if (envVersion === "trial") {
|
if (envVersion === "trial" || envVersion === "develop") {
|
||||||
console.log(...args);
|
console.log(...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,6 +130,7 @@ class AudioManager {
|
|||||||
// 防重复播放保护
|
// 防重复播放保护
|
||||||
this.lastPlayKey = null;
|
this.lastPlayKey = null;
|
||||||
this.lastPlayAt = 0;
|
this.lastPlayAt = 0;
|
||||||
|
this.isInterrupted = false;
|
||||||
|
|
||||||
// 静音开关
|
// 静音开关
|
||||||
this.isMuted = false;
|
this.isMuted = false;
|
||||||
@@ -141,10 +145,41 @@ class AudioManager {
|
|||||||
this.localFileCache = uni.getStorageSync("audio_local_files") || {};
|
this.localFileCache = uni.getStorageSync("audio_local_files") || {};
|
||||||
// 启动时自动清理过期的缓存文件(URL 已不在 audioFils 中的文件)
|
// 启动时自动清理过期的缓存文件(URL 已不在 audioFils 中的文件)
|
||||||
this.cleanObsoleteCache();
|
this.cleanObsoleteCache();
|
||||||
|
this.bindAudioInterruptionEvents();
|
||||||
|
|
||||||
this.initAudios();
|
this.initAudios();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bindAudioInterruptionEvents() {
|
||||||
|
if (this._audioInterruptionBound) return;
|
||||||
|
this._audioInterruptionBound = true;
|
||||||
|
|
||||||
|
const begin = () => {
|
||||||
|
if (this.isInterrupted) return;
|
||||||
|
this.isInterrupted = true;
|
||||||
|
this.stopAll();
|
||||||
|
this.isSequenceRunning = false;
|
||||||
|
this.sequenceQueue = [];
|
||||||
|
this.sequenceIndex = 0;
|
||||||
|
this.pendingPlayKey = null;
|
||||||
|
uni.$emit(AUDIO_INTERRUPTION_BEGIN_EVENT);
|
||||||
|
};
|
||||||
|
|
||||||
|
const end = () => {
|
||||||
|
if (!this.isInterrupted) return;
|
||||||
|
this.isInterrupted = false;
|
||||||
|
uni.$emit(AUDIO_INTERRUPTION_END_EVENT);
|
||||||
|
void this.reloadAll();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof uni?.onAudioInterruptionBegin === "function") {
|
||||||
|
uni.onAudioInterruptionBegin(begin);
|
||||||
|
}
|
||||||
|
if (typeof uni?.onAudioInterruptionEnd === "function") {
|
||||||
|
uni.onAudioInterruptionEnd(end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 清理不再使用的缓存文件
|
// 清理不再使用的缓存文件
|
||||||
cleanObsoleteCache() {
|
cleanObsoleteCache() {
|
||||||
const activeUrls = new Set(Object.values(audioFils));
|
const activeUrls = new Set(Object.values(audioFils));
|
||||||
@@ -461,6 +496,10 @@ class AudioManager {
|
|||||||
|
|
||||||
// 播放指定音频或音频数组(数组则按顺序连续播放)
|
// 播放指定音频或音频数组(数组则按顺序连续播放)
|
||||||
play(input, interrupt = true) {
|
play(input, interrupt = true) {
|
||||||
|
if (this.isInterrupted) {
|
||||||
|
debugLog("音频处理中断状态,忽略播放请求");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 统一规范化为队列
|
// 统一规范化为队列
|
||||||
let queue = [];
|
let queue = [];
|
||||||
if (Array.isArray(input)) {
|
if (Array.isArray(input)) {
|
||||||
@@ -514,6 +553,10 @@ class AudioManager {
|
|||||||
|
|
||||||
// 内部方法:播放单个 key
|
// 内部方法:播放单个 key
|
||||||
_playSingle(key, forceStopAll = false) {
|
_playSingle(key, forceStopAll = false) {
|
||||||
|
if (this.isInterrupted) {
|
||||||
|
debugLog(`音频处理中断状态,跳过播放: ${key}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 200ms 内的同 key 重复播放直接忽略,避免“比比赛开始”这类重复首音
|
// 200ms 内的同 key 重复播放直接忽略,避免“比比赛开始”这类重复首音
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (this.lastPlayKey === key && now - this.lastPlayAt < 250) {
|
if (this.lastPlayKey === key && now - this.lastPlayAt < 250) {
|
||||||
@@ -557,7 +600,13 @@ class AudioManager {
|
|||||||
// 显式授权播放并立即播放
|
// 显式授权播放并立即播放
|
||||||
this.allowPlayMap.set(key, true);
|
this.allowPlayMap.set(key, true);
|
||||||
|
|
||||||
audio.play();
|
try {
|
||||||
|
audio.play();
|
||||||
|
} catch (err) {
|
||||||
|
this.allowPlayMap.set(key, false);
|
||||||
|
debugLog(`音频 ${key} 播放调用失败`, err?.errMsg || err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.currentPlayingKey = key;
|
this.currentPlayingKey = key;
|
||||||
this.lastPlayKey = key;
|
this.lastPlayKey = key;
|
||||||
this.lastPlayAt = Date.now();
|
this.lastPlayAt = Date.now();
|
||||||
|
|||||||
@@ -24,12 +24,14 @@ const onUpdateTips = (newVal) => {
|
|||||||
|
|
||||||
// 监听 Pinia store 中 totalShot 变化,用于比赛恢复时同步箭数(替代 uni.$emit 避免时序问题)
|
// 监听 Pinia store 中 totalShot 变化,用于比赛恢复时同步箭数(替代 uni.$emit 避免时序问题)
|
||||||
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决重入时 totalShot 值不变 watch 不触发的问题)
|
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决重入时 totalShot 值不变 watch 不触发的问题)
|
||||||
watch(() => store.game.totalShot, (newVal) => {
|
watch(
|
||||||
if (newVal > 0) {
|
() => [store.game.currentShot, store.game.totalShot],
|
||||||
totalShot.value = newVal;
|
([newCurrentShot, newTotalShot]) => {
|
||||||
currentShot.value = store.game.currentShot;
|
currentShot.value = newCurrentShot || 0;
|
||||||
}
|
totalShot.value = newTotalShot || 0;
|
||||||
}, { immediate: true });
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
// 监听 Pinia store 中 tips 变化,用于比赛恢复时同步提示文案(替代 uni.$emit 避免时序问题)
|
// 监听 Pinia store 中 tips 变化,用于比赛恢复时同步提示文案(替代 uni.$emit 避免时序问题)
|
||||||
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决 onShow 早于 onMounted 导致 uni.$emit 事件丢失的问题)
|
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决 onShow 早于 onMounted 导致 uni.$emit 事件丢失的问题)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
total: {
|
total: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 15,
|
default: 12,
|
||||||
},
|
},
|
||||||
currentRound: {
|
currentRound: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -18,9 +18,9 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const barColor = ref("");
|
const barColor = ref("");
|
||||||
const remain = ref(15);
|
const remain = ref(12);
|
||||||
const timer = ref(null);
|
const timer = ref(null);
|
||||||
const loading = ref(false);
|
const loading = ref(true);
|
||||||
const transitionStyle = ref("all 1s linear");
|
const transitionStyle = ref("all 1s linear");
|
||||||
const currentTeam = ref(null);
|
const currentTeam = ref(null);
|
||||||
const MIN_TICK_MS = 1;
|
const MIN_TICK_MS = 1;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onBeforeUnmount, nextTick, watch } from "vue";
|
import { ref, onMounted, onBeforeUnmount, nextTick, watch } from "vue";
|
||||||
import { onLoad, onShow } from "@dcloudio/uni-app";
|
import { onHide, onLoad, onShow } from "@dcloudio/uni-app";
|
||||||
import Container from "./components/Container.vue";
|
import Container from "./components/Container.vue";
|
||||||
import BattleHeader from "./components/BattleHeader.vue";
|
import BattleHeader from "./components/BattleHeader.vue";
|
||||||
import BowTarget from "./components/BowTarget.vue";
|
import BowTarget from "./components/BowTarget.vue";
|
||||||
@@ -15,7 +15,10 @@ import SModal from "./components/SModal.vue";
|
|||||||
import { laserCloseAPI, getBattleAPI } from "@/apis";
|
import { laserCloseAPI, getBattleAPI } from "@/apis";
|
||||||
import { MESSAGETYPESV2 } from "@/constants";
|
import { MESSAGETYPESV2 } from "@/constants";
|
||||||
import { getDirectionText } from "@/util";
|
import { getDirectionText } from "@/util";
|
||||||
import audioManager from "@/audioManager";
|
import audioManager, {
|
||||||
|
AUDIO_INTERRUPTION_BEGIN_EVENT,
|
||||||
|
AUDIO_INTERRUPTION_END_EVENT,
|
||||||
|
} from "@/audioManager";
|
||||||
import useStore from "@/store";
|
import useStore from "@/store";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
|
|
||||||
@@ -402,6 +405,20 @@ function onAudioEnded(key) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleBattleCovered() {
|
||||||
|
if (pendingRestoreTimer) {
|
||||||
|
clearTimeout(pendingRestoreTimer);
|
||||||
|
pendingRestoreTimer = null;
|
||||||
|
}
|
||||||
|
hideRestoreLoading();
|
||||||
|
pendingRoundAudio = false;
|
||||||
|
invalidateBattleQueue({ stopAudio: true, stopProgress: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBattleRecovered() {
|
||||||
|
scheduleRestoreLatestBattle();
|
||||||
|
}
|
||||||
|
|
||||||
// 队伍信息优先用接口返回值;接口缺失时使用本地缓存,避免重进页面时头像为空。
|
// 队伍信息优先用接口返回值;接口缺失时使用本地缓存,避免重进页面时头像为空。
|
||||||
function loadTeamPlayers(teamInfo, storageKey) {
|
function loadTeamPlayers(teamInfo, storageKey) {
|
||||||
if (Array.isArray(teamInfo?.players)) return [...teamInfo.players];
|
if (Array.isArray(teamInfo?.players)) return [...teamInfo.players];
|
||||||
@@ -995,6 +1012,8 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
uni.$on("socket-inbox", onReceiveMessage);
|
uni.$on("socket-inbox", onReceiveMessage);
|
||||||
uni.$on("audioEnded", onAudioEnded);
|
uni.$on("audioEnded", onAudioEnded);
|
||||||
|
uni.$on(AUDIO_INTERRUPTION_BEGIN_EVENT, handleBattleCovered);
|
||||||
|
uni.$on(AUDIO_INTERRUPTION_END_EVENT, handleBattleRecovered);
|
||||||
uni.$on(PROGRESS_ZERO_EVENT, onProgressZero);
|
uni.$on(PROGRESS_ZERO_EVENT, onProgressZero);
|
||||||
uni.$on(COUNTDOWN_READY_EVENT, hideRestoreLoading);
|
uni.$on(COUNTDOWN_READY_EVENT, hideRestoreLoading);
|
||||||
await laserCloseAPI();
|
await laserCloseAPI();
|
||||||
@@ -1015,9 +1034,17 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
hideRestoreLoading();
|
hideRestoreLoading();
|
||||||
invalidateBattleQueue({ stopAudio: true, stopProgress: true });
|
invalidateBattleQueue({ stopAudio: true, stopProgress: true });
|
||||||
|
console.log('onBeforeUnmount', '页面卸载前')
|
||||||
audioManager.stopAll();
|
audioManager.stopAll();
|
||||||
|
uni.$off(AUDIO_INTERRUPTION_BEGIN_EVENT, handleBattleCovered);
|
||||||
|
uni.$off(AUDIO_INTERRUPTION_END_EVENT, handleBattleRecovered);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onHide(()=>{
|
||||||
|
console.log('onHide', '页面大退')
|
||||||
|
handleBattleCovered();
|
||||||
|
})
|
||||||
|
|
||||||
// 每次回到前台都重新拉最新比赛快照,确保画面与后端一致。
|
// 每次回到前台都重新拉最新比赛快照,确保画面与后端一致。
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
console.log('onshow')
|
console.log('onshow')
|
||||||
|
|||||||
Reference in New Issue
Block a user