react-native-audio-recorder-player
react-native-audio-recorder-player copied to clipboard
Android - Keep playing the previous audio
Version of react-native-audio-recorder-player
3.5.1
Version of React Native
0.69.5
Platforms you faced the error (IOS or Android or both?)
Android
Expected behavior
It should start playing with the new audio url
Actual behavior
It keeps playing the previous audio
Steps to reproduce the behavior
Play the first audio link Then play the other audio link Observe the result
@suupham2506 did you found the solution of it? I'm facing the same.
not yet @Steve-Rynjah , I am waiting for @hyochan Hy
Uploading Simulator Screen Recording - iPhone 14 Pro - 2022-12-04 at 20.21.08.mp4…
@suupham2506 How did you pass the path
? I couldn't reproduce this 🤔
I'm also experiencing this. Note that it is happening in Android only:
Repro steps using example:
- Record with file path A
- Play back path A (partial)
- Record with file path B
- Play back path B
Expect to hear file path B; instead file path A picks up where it left off. Path B starts to play only after A has completed playing.
It's as if there's some caching in the Android player. I've even tried deleting file A but it still plays in step 4.
UPDATE:
I've been able to hack a fix by adding seekToPlayer(0)
before recording the second file. I think this is because at https://github.com/hyochan/react-native-audio-recorder-player/blob/main/android/src/main/java/com/dooboolab.audiorecorderplayer/RNAudioRecorderPlayerModule.kt#L192 the player assumes I'm resuming unless the duration is at 0.
I'm not sure if this is a bug or intentional? Is there some other way to reset the player so that the old cache is destroyed?
const onStopPlay = useCallback(async () => { if (audioRecorderPlayer?._isPlaying) { audioRecorderPlayer.stopPlayer(); audioRecorderPlayer.removePlayBackListener(); setIsPlaying(false); setPlayTime(0); setProgress(0); } }, [audioRecorderPlayer]);
useEffect(() => { return () => { if (isPlaying) { console.log('onStop'); onStopPlay(); } }; }, [isPlaying, onStopPlay]);
When I move the screen while playing, This is how I handled it. Hope this helps.