BUG修复
This commit is contained in:
@@ -88,6 +88,20 @@ class AudioManager {
|
||||
this.isLoading = false;
|
||||
this.loadingPromise = null;
|
||||
|
||||
// 网络状态相关
|
||||
this.networkOnline = true;
|
||||
this.pendingPlayKey = null;
|
||||
try {
|
||||
uni.onNetworkStatusChange(({ isConnected }) => {
|
||||
this.networkOnline = !!isConnected;
|
||||
if (this.networkOnline) {
|
||||
this.onNetworkRestored();
|
||||
} else {
|
||||
this.onNetworkLost();
|
||||
}
|
||||
});
|
||||
} catch (_) {}
|
||||
|
||||
this.initAudios();
|
||||
}
|
||||
|
||||
@@ -210,6 +224,11 @@ class AudioManager {
|
||||
|
||||
// 处理音频加载错误
|
||||
handleAudioError(key) {
|
||||
// 网络不可用时不重试,等重连后统一重建
|
||||
if (!this.networkOnline) {
|
||||
debugLog(`网络不可用,暂不重试音频: ${key}`);
|
||||
return;
|
||||
}
|
||||
const currentRetries = this.retryCount.get(key) || 0;
|
||||
|
||||
if (currentRetries < this.maxRetries) {
|
||||
@@ -233,6 +252,10 @@ class AudioManager {
|
||||
|
||||
// 重新加载音频
|
||||
retryLoadAudio(key) {
|
||||
if (!this.networkOnline) {
|
||||
debugLog(`网络不可用,稍后再重载音频: ${key}`);
|
||||
return;
|
||||
}
|
||||
const oldAudio = this.audioMap.get(key);
|
||||
if (oldAudio) {
|
||||
oldAudio.destroy();
|
||||
@@ -242,6 +265,12 @@ class AudioManager {
|
||||
|
||||
// 播放指定音频
|
||||
play(key) {
|
||||
// 离线:缓存播放意图,待网络恢复后自动播放
|
||||
if (!this.networkOnline) {
|
||||
this.pendingPlayKey = key;
|
||||
debugLog(`网络不可用,记录播放意图: ${key}`);
|
||||
return;
|
||||
}
|
||||
// 覆盖播放:若当前播放且不是同一音频,先停止当前播放
|
||||
if (this.currentPlayingKey && this.currentPlayingKey !== key) {
|
||||
this.stop(this.currentPlayingKey);
|
||||
@@ -314,6 +343,32 @@ class AudioManager {
|
||||
this.currentPlayingKey = null;
|
||||
}
|
||||
|
||||
// 断网回调:停止当前播放,避免误状态
|
||||
onNetworkLost() {
|
||||
try {
|
||||
this.stopAll();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// 重连回调:重建全部音频后,重放上一次的播放意图
|
||||
onNetworkRestored() {
|
||||
this.reinitializeOnReconnect();
|
||||
if (this.pendingPlayKey) {
|
||||
const key = this.pendingPlayKey;
|
||||
this.pendingPlayKey = null;
|
||||
// 避免与初始化竞态,轻微延迟后播放
|
||||
setTimeout(() => {
|
||||
this.play(key);
|
||||
}, 20);
|
||||
}
|
||||
}
|
||||
|
||||
// 重连后统一重建音频实例
|
||||
reinitializeOnReconnect() {
|
||||
this.destroyAll();
|
||||
this.initAudios();
|
||||
}
|
||||
|
||||
// 手动重新加载指定音频
|
||||
reloadAudio(key) {
|
||||
if (audioFils[key]) {
|
||||
|
||||
@@ -140,8 +140,27 @@ onBeforeUnmount(() => {
|
||||
left: calcRealX(latestOne.ring ? latestOne.x : 0, 28),
|
||||
top: calcRealY(latestOne.ring ? latestOne.y : 0, 28),
|
||||
}"
|
||||
>{{ latestOne.ring || "未上靶"
|
||||
}}<text v-if="latestOne.ring">环</text></view
|
||||
>{{ latestOne.ring || "未上靶" }}<text v-if="latestOne.ring">环</text>
|
||||
</view>
|
||||
<view
|
||||
v-if="bluelatestOne && user.id === bluelatestOne.playerId"
|
||||
class="e-value fade-in-out"
|
||||
:style="{
|
||||
left: calcRealX(bluelatestOne.ring ? bluelatestOne.x : 0, 20),
|
||||
top: calcRealY(bluelatestOne.ring ? bluelatestOne.y : 0, 40),
|
||||
}"
|
||||
>
|
||||
经验 +1
|
||||
</view>
|
||||
<view
|
||||
v-if="bluelatestOne"
|
||||
class="round-tip fade-in-out"
|
||||
:style="{
|
||||
left: calcRealX(bluelatestOne.ring ? bluelatestOne.x : 0, 28),
|
||||
top: calcRealY(bluelatestOne.ring ? bluelatestOne.y : 0, 28),
|
||||
}"
|
||||
>{{ bluelatestOne.ring || "未上靶"
|
||||
}}<text v-if="bluelatestOne.ring">环</text></view
|
||||
>
|
||||
<block v-for="(bow, index) in scores" :key="index">
|
||||
<view
|
||||
|
||||
Reference in New Issue
Block a user