doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.18k stars 981 forks source link

track is fetched and playing but sound is not coming from speaker react-native-track-player #2222

Closed ahaseeb001 closed 6 months ago

ahaseeb001 commented 6 months ago

Describe the Bug

The track is successfully added into a queue and playing but after dragging multiple times like left or right the track shows it playing but the sound is not coming from the speaker when I press pause and then play everything works fine like the track is playing and sound is coming from the speaker. testing on IOS! here is the code step-by-step

Steps To Reproduce

step 1: adding tracks into the queue

const setUpTrackPlayer = async () => { try { setisLoading(true) const findIndex = AudioTracksLists.findIndex(val => val.id == EPI_OBJ.id); await TrackPlayer.reset(); await TrackPlayer.add(AudioTracksLists); const queue = await TrackPlayer.getQueue(); if (queue && queue.length > findIndex) { const selectedTrack = queue[findIndex]; await TrackPlayer.skip(findIndex); await TrackPlayer.play(); const isTrackPlayed = await TrackPlayer.getPlayWhenReady(); setisLoading(false); setisPlaying(isTrackPlayed); dispatch(EpisodsDataAction(BOOK_DATA)); dispatch(AudioPlayingAction(true)); console.log('audio is playing --->>>> '); } else { dispatch(AudioPlayingAction(false)); setisPlaying(false); setisLoading(false); console.log('audio is NOT playing --->>>> '); } } catch (e) { console.log( '🚀 🚀 ~ file: AudioPlayer.js:273 ~ setUpTrackPlayer ~ e:', e, ); } };

Step 2 :

const progress = useProgress();

const updateProgressPositionValue = parseInt(progress?.position?.toFixed(0));

const onSeekTo = async v => { const updateValue = parseInt(v?.toFixed(0)); try { setisLoading(true); await TrackPlayer.pause(); await TrackPlayer.seekTo(updateValue); setProgressPositionValue(updateValue); await TrackPlayer.play(); const isReady = await TrackPlayer.getPlayWhenReady(); setisLoading(false); setisPlaying(true); } catch (error) { console.log( '🚀 🚀 ~ file: AudioPlayer.js:160 ~ onSeekTo ~ error:', error, ); } };

<Slider
          thumbTintColor={App_Colors.White}
          style={{width: 350, height: 10}}
          value={parseInt(progressPositionValue?.toFixed(0))}
          minimumValue={0}
          maximumValue={parseInt(progress?.duration?.toFixed(0))}
          minimumTrackTintColor={App_Colors.White}
          maximumTrackTintColor="#9e9e9e"
          onSlidingComplete={v => onSeekTo(v)}
        />

useEffect(() => { setProgressPositionValue(updateProgressPositionValue); }, [updateProgressPositionValue]);

Library info : "react-native": "0.69.5", "react": "18.0.0", "@react-native-community/slider": "^4.3.1", "react-native-track-player": "4.0.1",

jspizziri commented 6 months ago

Your issue commenting needs work. Also, I'm not able to reproduce this issue.