修复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 { } catch {
host = '' host = ''
} }
return { return {
rawUrl, rawUrl,
protocol: protocolMatch?.[1]?.toLowerCase() || '', protocol: protocolMatch?.[1]?.toLowerCase() || '',
@@ -249,31 +250,30 @@ export default function ChatDetail() {
useEffect(() => { useEffect(() => {
if (typeof Taro.createInnerAudioContext !== 'function') { if (typeof Taro.createInnerAudioContext !== 'function') {
console.warn('[audio] InnerAudioContext unavailable', runtimeInfoRef.current) console.warn('[audio] InnerAudioContext unavailable');
return return;
} }
const audioContext = Taro.createInnerAudioContext() // 关键1: 忽略 iOS 静音开关
audioContextRef.current = audioContext Taro.setInnerAudioOption({ obeyMuteSwitch: false });
// 关键2: 使用 useWebAudioImplement 尝试绕过原生问题
const audioContext = Taro.createInnerAudioContext({
useWebAudioImplement: true, // 基础库 2.19.0+
});
audioContextRef.current = audioContext;
audioContext.onEnded(() => { audioContext.onEnded(() => {
console.info('[audio] ended', { playingMessageId: playingMessageIdRef.current }) setPlayingMessageId(null);
setPlayingMessageId(null) });
})
audioContext.onStop(() => { audioContext.onStop(() => {
console.info('[audio] stopped', { playingMessageId: playingMessageIdRef.current }) setPlayingMessageId(null);
setPlayingMessageId(null) });
})
audioContext.onError((error) => { audioContext.onError((error) => {
setPlayingMessageId(null) console.error('[audio] error detail:', JSON.stringify(error));
console.error('[audio] error', { setPlayingMessageId(null);
playingMessageId: playingMessageIdRef.current, Taro.showToast({ title: `播放失败: ${error.errMsg || '错误'}`, icon: 'none' });
src: audioContext.src, });
error,
runtime: runtimeInfoRef.current,
})
Taro.showToast({ title: '语音播放失败', icon: 'none' })
})
audioContext.onPlay(() => { audioContext.onPlay(() => {
console.info('[audio] play event', { playingMessageId: playingMessageIdRef.current, src: audioContext.src }) 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): if not await is_device_sleep(device_id):
return JSONResponse( return JSONResponse(
status_code=400, # 或 403 / 409 status_code=400, # 或 403 / 409
content={"detail": f"设备 {device_id} 不在线或已配置睡眠时间,请稍后再试"} content={"detail": f"设备不在线或在休眠中"}
) )
else: else:
# 路径格式不符合预期,可以放行或返回错误(根据业务决定) # 路径格式不符合预期,可以放行或返回错误(根据业务决定)