修复ios播放音频问题,修复休眠时段操作小程序加提示问题。

This commit is contained in:
HycJack
2026-05-26 02:18:00 +08:00
parent f9f1183e4b
commit e3059304b4
2 changed files with 20 additions and 20 deletions

View File

@@ -173,6 +173,7 @@ function getAudioUrlDebugInfo(rawUrl: string) {
} catch {
host = ''
}
return {
rawUrl,
protocol: protocolMatch?.[1]?.toLowerCase() || '',
@@ -249,31 +250,30 @@ export default function ChatDetail() {
useEffect(() => {
if (typeof Taro.createInnerAudioContext !== 'function') {
console.warn('[audio] InnerAudioContext unavailable', runtimeInfoRef.current)
return
console.warn('[audio] InnerAudioContext unavailable');
return;
}
const audioContext = Taro.createInnerAudioContext()
audioContextRef.current = audioContext
// 关键1: 忽略 iOS 静音开关
Taro.setInnerAudioOption({ obeyMuteSwitch: false });
// 关键2: 使用 useWebAudioImplement 尝试绕过原生问题
const audioContext = Taro.createInnerAudioContext({
useWebAudioImplement: true, // 基础库 2.19.0+
});
audioContextRef.current = audioContext;
audioContext.onEnded(() => {
console.info('[audio] ended', { playingMessageId: playingMessageIdRef.current })
setPlayingMessageId(null)
})
setPlayingMessageId(null);
});
audioContext.onStop(() => {
console.info('[audio] stopped', { playingMessageId: playingMessageIdRef.current })
setPlayingMessageId(null)
})
setPlayingMessageId(null);
});
audioContext.onError((error) => {
setPlayingMessageId(null)
console.error('[audio] error', {
playingMessageId: playingMessageIdRef.current,
src: audioContext.src,
error,
runtime: runtimeInfoRef.current,
})
Taro.showToast({ title: '语音播放失败', icon: 'none' })
})
console.error('[audio] error detail:', JSON.stringify(error));
setPlayingMessageId(null);
Taro.showToast({ title: `播放失败: ${error.errMsg || '错误'}`, icon: 'none' });
});
audioContext.onPlay(() => {
console.info('[audio] play event', { playingMessageId: playingMessageIdRef.current, src: audioContext.src })
})

View File

@@ -187,7 +187,7 @@ def install_auth_middleware(app: FastAPI) -> None:
if not await is_device_sleep(device_id):
return JSONResponse(
status_code=400, # 或 403 / 409
content={"detail": f"设备 {device_id} 不在线或已配置睡眠时间,请稍后再试"}
content={"detail": f"设备不在线或在休眠中"}
)
else:
# 路径格式不符合预期,可以放行或返回错误(根据业务决定)