Repository navigation
Androidでexpo-audioからエラーイベントがJSへ届かずTTS再生パイプラインが長時間ロックされる問題をストール検知ウォッチドッグで修正 - #6163
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughウォークスルーAndroid ネイティブオーディオで didJustFinish/error 未到来の停止を setInterval ポーリングで検知し、stalled 時に onError('Playback stalled') を返すウォッチドッグを追加。playAudio のコールバック統合と listener/remove の監視解除を一貫化。useTTS の EN プレイヤー生成時の例外処理と関連テストを拡張。 チェンジTTS 再生ストール検知メカニズム
シーケンスダイアグラムsequenceDiagram
participant Caller as 呼び出し元 (useTTS等)
participant PlayAudio as playAudio (ウォッチドッグ)
participant Player as player (Expo.Audio)
participant Settle as settle (コールバック統合)
Caller->>PlayAudio: playAudio(player, onFinish, onError)
PlayAudio->>Player: player.play()
PlayAudio->>Player: playbackStatusUpdate リスナー登録
PlayAudio->>PlayAudio: setInterval 開始 (player.playing/currentTime 監視)
Note over PlayAudio: ストール監視ループ開始
alt 正常にイベント受信
Player->>PlayAudio: didJustFinish / error
PlayAudio->>Settle: settle() -> onFinish/onError
else ストール検知
PlayAudio->>PlayAudio: stalledTicks 増加 -> max 到達
PlayAudio->>Settle: settle(new Error('Playback stalled'))
end
Settle->>PlayAudio: clearInterval 停止
Settle->>Player: listener.remove()
Settle->>Caller: onFinish / onError 実行
推定コード レビュー時間🎯 3 (Moderate) | ⏱️ ~25 分 提案ラベル
ポエム
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/ttsAudioPlayer.test.ts (1)
181-200: 💤 Low value
console.warnspy の検証を追加することを検討してください
warnSpyを設定していますが、実際にストール時の警告メッセージが出力されたかの検証がありません。ストール検知のログ出力も意図した動作の一部であれば、アサーションを追加するとテストの信頼性が向上します。♻️ 提案する修正
jest.advanceTimersByTime(STALL_TIMEOUT_MS + STALL_CHECK_INTERVAL_MS); expect(onError).toHaveBeenCalledTimes(1); expect(onError).toHaveBeenCalledWith(expect.any(Error)); expect(onFinish).not.toHaveBeenCalled(); expect(mock.listenerRemove).toHaveBeenCalledTimes(1); + expect(warnSpy).toHaveBeenCalledWith( + '[ttsAudioPlayer] playback stalled, aborting:', + 'stalled.mp3' + ); warnSpy.mockRestore();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/ttsAudioPlayer.test.ts` around lines 181 - 200, The test sets a console.warn spy (warnSpy) but never asserts it was called; update the test for the stalled-play scenario to assert that console.warn was invoked with the expected warning when playAudio detects a stall: after advancing timers (using STALL_TIMEOUT_MS and STALL_CHECK_INTERVAL_MS) add assertions that warnSpy was called (e.g., toHaveBeenCalledTimes(1)) and that it was called with a message or pattern indicating a stall (use expect.any(String) or a substring match), keeping the existing assertions for onError/onFinish and listener removal; reference the mock setup via createMockPlayer/mockCreateAudioPlayer and the playAudio call to locate the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils/ttsAudioPlayer.test.ts`:
- Around line 181-200: The test sets a console.warn spy (warnSpy) but never
asserts it was called; update the test for the stalled-play scenario to assert
that console.warn was invoked with the expected warning when playAudio detects a
stall: after advancing timers (using STALL_TIMEOUT_MS and
STALL_CHECK_INTERVAL_MS) add assertions that warnSpy was called (e.g.,
toHaveBeenCalledTimes(1)) and that it was called with a message or pattern
indicating a stall (use expect.any(String) or a substring match), keeping the
existing assertions for onError/onFinish and listener removal; reference the
mock setup via createMockPlayer/mockCreateAudioPlayer and the playAudio call to
locate the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f2b79888-5165-43ff-bbce-fa4c87ec1d0e
📒 Files selected for processing (4)
src/hooks/useTTS.test.tssrc/hooks/useTTS.tssrc/utils/ttsAudioPlayer.test.tssrc/utils/ttsAudioPlayer.ts
概要
Android版でTTSがとあるタイミングで全く再生されなくなる問題の調査と修正。
expo-audio 55.0.13のAndroidネイティブ実装(
AudioPlayer.kt)にはPlayer.Listener#onPlayerErrorが実装されておらず、ExoPlayerが再生エラーで停止してもJSへはerrorイベントもdidJustFinishも届かない。また音声フォーカスの恒久喪失(AUDIOFOCUS_LOSS)時は全プレイヤーが無通知でpauseされ自動復帰しない。この状態に陥るとuseTTSのplayingRefが300秒のセーフティタイムアウトまでロックされ、その間のアナウンスはすべて握り潰される(=他アプリの音声再生・フォーカス喪失・再生エラー直後にTTSが全く再生されない症状と一致)。playAudioに再生位置ポーリングによるストール検知ウォッチドッグを追加し、ネイティブからイベントが届かなくても約10秒で打ち切って次のアナウンスへ復帰できるようにした。変更の種類
変更内容
src/utils/ttsAudioPlayer.ts:playAudioに1秒間隔のストール検知ウォッチドッグを追加。player.playingとplayer.currentTimeをポーリングし、再生位置が10秒間進まなければonErrorで打ち切って再生パイプラインを解放する。完了・エラー・破棄時の二重発火はsettledフラグで防止し、リスナー解除と同時にウォッチドッグも確実に停止するsrc/hooks/useTTS.ts: 日本語再生完了後にsetTimeout内で英語プレイヤーを生成する箇所をtry/catchで保護(コールバック内の例外は誰もキャッチせずplayingRefがロックされたままになるため)。PLAYBACK_TIMEOUT_MSのコメントを実態(最終フォールバック)に合わせて更新src/utils/ttsAudioPlayer.test.ts/src/hooks/useTTS.test.ts: ストール検知・再生進行中の誤検知防止・完了/解除後のウォッチドッグ停止・ストールからの復帰シナリオのテストを追加テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ること関連Issue
スクリーンショット(任意)
Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests