react-native-audio-recorder-player icon indicating copy to clipboard operation
react-native-audio-recorder-player copied to clipboard

Android - Keep playing the previous audio

Open suupham2506 opened this issue 1 year ago • 5 comments

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 avatar Oct 29 '22 17:10 suupham2506

@suupham2506 did you found the solution of it? I'm facing the same.

Steve-Rynjah avatar Nov 10 '22 11:11 Steve-Rynjah

not yet @Steve-Rynjah , I am waiting for @hyochan Hy

suupham2506 avatar Nov 10 '22 16:11 suupham2506

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 🤔

hyochan avatar Dec 04 '22 11:12 hyochan

I'm also experiencing this. Note that it is happening in Android only:

Repro steps using example:

  1. Record with file path A
  2. Play back path A (partial)
  3. Record with file path B
  4. 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?

pjadavies avatar Feb 09 '23 01:02 pjadavies

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.

jkyoo82 avatar Sep 10 '23 00:09 jkyoo82