From 0bb8c2695fdf0bb706e169bbb6e3c8184167209d Mon Sep 17 00:00:00 2001 From: kron Date: Mon, 14 Jul 2025 16:37:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A3=B0=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/audioManager.js | 93 ++++++++++++++++++++++++++++ src/components/ShootProgress.vue | 101 +++++++++++++++++++++++-------- src/pages/first-try.vue | 3 + src/pages/practise-one.vue | 3 + src/pages/practise-two.vue | 3 + 5 files changed, 179 insertions(+), 24 deletions(-) create mode 100644 src/audioManager.js diff --git a/src/audioManager.js b/src/audioManager.js new file mode 100644 index 0000000..5be11b7 --- /dev/null +++ b/src/audioManager.js @@ -0,0 +1,93 @@ +const audioFils = { + 第一轮: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fl26qrspvy79.mp3", + 第二轮: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fehshrpe5ook.mp3", + 第三轮: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fgbz3iimk7yy.mp3", + 第四轮: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fjwf50tlxxbi.mp3", + 第五轮: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fg63lqrslhm7.mp3", + 决金箭轮: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fhjycwubbwil.mp3", + 请蓝方射击: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fr0zpluiabph.mp3", + 请红方射击: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fu169yerpwey.mp3", + 中场休息: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblu6fug8faqrbtwd.mp3", + 比赛结束: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblsdl717ilr0b3o0.mp3", + 比赛开始: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbblsdl7qlkqgvthfr.mp3", + 请开始射击: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbljrfx5guqt5oulk.mp3", + 未上靶: + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbkxm60bul0khcoqq.mp3", + "1环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbklufj59qmdo96ha.mp3", + "2环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbklufogy49ousbv4.mp3", + "3环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbklufl3hhijeasck.mp3", + "4环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbklufo8vo7k6jxdz.mp3", + "5环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbklkzq7lrbfpr6ij.mp3", + "6环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbkll0fw7hbmmhxkl.mp3", + "7环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbkll0fkirkanghmf.mp3", + "8环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbkll0cly2noykieg.mp3", + "9环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbkll0gsuumekhpkn.mp3", + "10环": + "https://api.shelingxingqiu.com/attachment/2025-07-14/dbbklgw2dk22ek7qha.mp3", +}; + +class AudioManager { + constructor() { + this.audioMap = new Map(); + Object.keys(audioFils).forEach((key) => { + const audio = uni.createInnerAudioContext(); + audio.src = audioFils[key]; + audio.autoplay = false; + + // 监听加载状态 + audio.onCanplay(() => { + console.log(`音频 ${key} 已加载完成`); + }); + + audio.onError((res) => { + console.log(`音频 ${key} 加载失败:`, res.errMsg); + }); + + this.audioMap.set(key, audio); + }); + } + + // 播放指定音频 + play(key) { + const audio = this.audioMap.get(key); + if (audio) audio.play(); + } + + // 停止指定音频 + stop(key) { + const audio = this.audioMap.get(key); + if (audio) audio.stop(); + } + + // 销毁所有音频实例 + destroyAll() { + this.audioMap.forEach((audio) => { + audio.destroy(); + }); + this.audioMap.clear(); + } +} + +// 导出单例 +export default new AudioManager(); diff --git a/src/components/ShootProgress.vue b/src/components/ShootProgress.vue index c286eee..b8a671c 100644 --- a/src/components/ShootProgress.vue +++ b/src/components/ShootProgress.vue @@ -1,5 +1,7 @@ @@ -107,7 +160,7 @@ onUnmounted(() => { {{ start && remain === 0 ? "时间到!" : tips }} -