react-native-track-player
react-native-track-player copied to clipboard
Not initialized player after unmounted UI on Android
Describe the Bug
Android only. Got error message :The player is not initialized. Call setupPlayer first.
after leaving the app in background for more than 5 minutes.
Steps To Reproduce
- open the app.
- call
.setupPlayer()
- call
.reset()
- call
.add(track)
- call
.play()
- let the track start
- call
.reset()
- leave app in background for 5 minutes
- call
.reset()
- call
.add(track)
- call
.play()
Code To Reproduce
// App.tsx in a componentDidMount
await TrackPlayer.setupPlayer()
// Player.tsx in an onPressTrack function
await TrackPlayer.reset()
await TrackPlayer.add(track)
await TrackPlayer.play()
Environment Info:
Tested on real devices and simulators
react-native-track-player: "2.2.0-rc4-e36a016d1640e75649d6da4056f8977da33864e1"
System:
OS: macOS 11.5.2
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 197.92 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
Android SDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7621141
Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
Languages:
Java: 14.0.2 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.68.2 => 0.68.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
How I can Help
Have you investigated the underlying JS or Swift/Android code causing this bug? Not yet
Quick fix:
// App.tsx in a componentDidMount
- await TrackPlayer.setupPlayer()
// Player.tsx in an onPressTrack function
+ await TrackPlayer.setupPlayer()
await TrackPlayer.reset()
await TrackPlayer.add(track)
await TrackPlayer.play()
You may catch The player has already been initialized via setupPlayer.
error to avoid useless Sentry
issues.
@devpolo we also encountered the same error even after less than 5 minutes. Unfortunately we noticed this problem after deploying the app in production and the audio does not start due to this problem.
@devpolo can you see if you're having this issue with the nightly
build or with 3.1
?
Closing due to inactivity.
same problem
Issue still exists in 3.2
same problem
still facing the same issue
still facing the same issue latest nightly build
@MortadhaFadhlaoui can you reproduce this issue using the example app?
@puckey I didn't try the example app, but i will give it a shot, but we can reproduce it in our app.
I will reopen this issue if you can reproduce in the example app (or in a forked version of the example app)
having this issue myself. but i call setup player in my playback service. i will try moving it outside
it seems the only way i could get this to work for android without making it crash was to call TrackPlayer.setupPlayer() twice. super weird
Same issue.
Getting the same error and our implementation is very similar to the example app.
Not yet happening in production, but on testing it seems to work fine despite getting this error in Sentry.
version: 3.2.0-bb749e5d286737681ba8907dfd287480eb1cec45
Same error and reproducible with latest package release and following the example code. I think this fix should be released to production because it happens frequently.
Debug Info:
"react-native-track-player": "^3.2.0",
WARN Possible Unhandled Promise Rejection (id: 0):
Error: The player is not initialized. Call setupPlayer first
I am still facing this error on sentry. Any possible Solution ?
The problem still exists in the latest 4.0.1
version. Android only. I get a lot of events on Sentry
The problem still exists in the latest
4.0.1
version. Android only. I get a lot of events on Sentry
Same, I also received crash logs in this version.
Same, I am still getting these on sentry, but its working fine for the user.
The player is not initialized. Call setupPlayer first.
I get this issue for only certain Android devices. Works fine for a majority of Android devices. OnePlus 10T seems to cause it a lot. Any workaround to catch this type of error? I guess you can catch it and then re-setup the player before attempting the event again?
I'm experiencing the same issue now. Doesn't work on my android emulator nor my android device.