I have a react-navigation modal with react-native-track-player, closing one and opening it back throws the error The player has already been initialized via setupPlayer
. How to make sure it runs only once? I couldn't find a method to do so.
useEffect(() => {
setupPlayer();
}, []);
const setupPlayer = async() => {
try {
await TrackPlayer.setupPlayer();
await TrackPlayer.updateOptions({
capabilities: [
Capability.Play,
Capability.Pause,
Capability.SkipToNext,
Capability.SkipToPrevious
],
});
await TrackPlayer.add(podcasts);
await gettrackdata();
await TrackPlayer.play();
} catch (error) {
console.log(error);
}
};