react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

Not initialized player after unmounted UI on Android

Open devpolo opened this issue 2 years ago • 1 comments

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

  1. open the app.
  2. call .setupPlayer()
  3. call .reset()
  4. call .add(track)
  5. call .play()
  6. let the track start
  7. call .reset()
  8. leave app in background for 5 minutes
  9. call .reset()
  10. call .add(track)
  11. 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

devpolo avatar Aug 08 '22 11:08 devpolo

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 avatar Aug 08 '22 11:08 devpolo

@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.

nicomontanari avatar Aug 25 '22 14:08 nicomontanari

@devpolo can you see if you're having this issue with the nightly build or with 3.1?

jspizziri avatar Sep 06 '22 15:09 jspizziri

Closing due to inactivity.

jspizziri avatar Sep 20 '22 14:09 jspizziri

same problem

omarabualhija avatar Nov 27 '22 12:11 omarabualhija

Issue still exists in 3.2

Malin88 avatar Dec 14 '22 13:12 Malin88

same problem

vickyCelstream avatar Dec 20 '22 06:12 vickyCelstream

still facing the same issue

bhaveshdotstudio avatar Dec 27 '22 12:12 bhaveshdotstudio

still facing the same issue latest nightly build

MortadhaFadhlaoui avatar Mar 28 '23 14:03 MortadhaFadhlaoui

@MortadhaFadhlaoui can you reproduce this issue using the example app?

puckey avatar Mar 28 '23 14:03 puckey

@puckey I didn't try the example app, but i will give it a shot, but we can reproduce it in our app.

MortadhaFadhlaoui avatar Mar 28 '23 20:03 MortadhaFadhlaoui

I will reopen this issue if you can reproduce in the example app (or in a forked version of the example app)

puckey avatar Mar 31 '23 09:03 puckey

having this issue myself. but i call setup player in my playback service. i will try moving it outside

NoodleOfDeath avatar Apr 28 '23 18:04 NoodleOfDeath

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

NoodleOfDeath avatar Apr 28 '23 18:04 NoodleOfDeath

Same issue.

justintoth avatar May 05 '23 01:05 justintoth

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

RamProg avatar May 11 '23 19:05 RamProg

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

ofattouh avatar May 28 '23 23:05 ofattouh

I am still facing this error on sentry. Any possible Solution ?

cactusanil avatar Jun 02 '23 10:06 cactusanil

The problem still exists in the latest 4.0.1 version. Android only. I get a lot of events on Sentry

takacskalman avatar Nov 30 '23 08:11 takacskalman

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.

krinish291 avatar Dec 02 '23 13:12 krinish291

Same, I am still getting these on sentry, but its working fine for the user. The player is not initialized. Call setupPlayer first.

saracasticshailz avatar Dec 28 '23 09:12 saracasticshailz

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?

SteveWaterfall avatar Feb 25 '24 16:02 SteveWaterfall

I'm experiencing the same issue now. Doesn't work on my android emulator nor my android device.

marvelous-ikechi avatar Mar 15 '24 18:03 marvelous-ikechi