fix(expo): 暂停自动朗读后继续播放最新 TTS 片段
- usePlayer:paused 且 tts_auto 时清空队列并重置,再播当前片段 - 用 statusRef 与暂停同步,避免 WS 紧连 enqueue 时状态滞后 - 补充 use-player 单测 - api: 调整 copyright_source_pdf 脚本 - docs: 新增软著《岁月时书》软件设计说明书 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -167,4 +167,44 @@ describe('usePlayer', () => {
|
||||
expect(acquire).toHaveBeenCalledTimes(2);
|
||||
expect(play).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('after pause, new tts_auto clears backlog and kicks playNext', async () => {
|
||||
mockUseAudioPlayerStatus.mockReturnValue({
|
||||
isLoaded: true,
|
||||
playing: false,
|
||||
currentTime: 0.1,
|
||||
duration: 10,
|
||||
});
|
||||
const pause = jest.fn();
|
||||
const play = jest.fn();
|
||||
mockUseAudioPlayer.mockReturnValue({ pause, play });
|
||||
|
||||
const { result } = renderHook(() => usePlayer());
|
||||
|
||||
await act(async () => {
|
||||
await result.current.enqueue({
|
||||
uri: 'file:///first.mp3',
|
||||
kind: 'tts_auto',
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.status).toBe('playing');
|
||||
const playCountAfterFirst = play.mock.calls.length;
|
||||
|
||||
act(() => {
|
||||
result.current.pausePlayback();
|
||||
});
|
||||
expect(result.current.status).toBe('paused');
|
||||
|
||||
await act(async () => {
|
||||
await result.current.enqueue({
|
||||
uri: 'file:///latest.mp3',
|
||||
kind: 'tts_auto',
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.status).toBe('playing');
|
||||
expect(play.mock.calls.length).toBeGreaterThan(playCountAfterFirst);
|
||||
expect(result.current.currentSource).toBe('file:///latest.mp3');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user