react-native-track-player: [Android] [nightly] Calling TrackPlayer.reset causes Android app to crash

Describe the Bug Calling TrackPlayer.reset causes Android app to crash

Steps To Reproduce

  1. Run example android app - https://github.com/doublesymmetry/react-native-track-player/tree/main/example
  2. Add Button with TrackPlayer.reset
  3. Press the reset button (does not matter if track is being played or stopped)
  4. App crashes

Code To Reproduce Add this code after <PlayPauseButton /> in example/src/components/PlayerControls.tsx

<Button
  title="Reset"
  onPress={() => TrackPlayer.reset()}
  type="secondary"
/>

Replicable on Example App? Yes

Environment Info: Paste the results of npx react-native info -

System: OS: macOS 12.6 CPU: (8) arm64 Apple M1 Pro Memory: 294.03 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.17.1 - /opt/homebrew/opt/node@16/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 8.15.0 - /opt/homebrew/opt/node@16/bin/npm Watchman: 2022.10.03.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: API Levels: 29, 30, 31, 32, 33 Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0 System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play ARM 64 v8a, android-30 | Google Play Intel x86 Atom, android-31 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.0/14A309 - /usr/bin/xcodebuild Languages: Java: 11.0.11 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: Not Found react-native: Not Found react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Paste the exact react-native-track-player version you are using - nightly build (main branch) Real device? - Or simulator? Both real device and simulator What OS are you running? - macOS Monterey (12.6)

How I can Help What can you do to help resolve this? - Participate in discussion Have you investigated the underlying JS or Swift/Android code causing this bug? - Yes, could not find any useful info to help identify the problem Can you create a Pull Request with a fix? - Not yet

https://user-images.githubusercontent.com/55248414/203612323-85b7a825-c53e-4296-8f19-8ab9aab5dd09.mov

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 24 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@jspizziri Sorry for the inconvenience. I think it may have been overlooked. I opened a pr for this topic.

In my case I’m using reset to stop whatever is playing (if anything) and replace it with a new track. It’s a single track app, as I either play a live radio stream, or a recorded radio program. Is there a workaround for reset in this scenario? I’m thinking maybe I could pause and remove a currently loaded track if there is one, instead of calling reset. I don’t know if that would make a difference though.

@jspizziri great – I was able to fix things by incorporating one of the commits from that pr. See https://github.com/doublesymmetry/react-native-track-player/pull/1908

Will look into this other PR – looks promising.

Okay good to know – so the unwanted side-effect caused by removing exitProcess(0) is that exiting the app by swiping it away in the app switcher does initially cause the notification to be removed. But when opening the app again, starting playing and swiping away to exit again, the music keeps playing and the notification doesn’t go away. Hm.

In case this helps someone, what I’m doing temporarily is (only for Android):

        await TrackPlayer.removeUpcomingTracks();
        await TrackPlayer.pause();
        await TrackPlayer.add(queue);
        await TrackPlayer.skipToNext();
        await TrackPlayer.play();

I am currently trying to resolve this issue. The information I have so far is as follows: If Capability -> Stop button is used, the foreground service is stopped completely.

In the current structure, if the application is closed on the android side and the process.exit() in the code is not used, the foreground service does not stop.

So I am trying to achieve Capability -> Stop behavior during STOP_PLAYBACK_AND_REMOVE_NOTIFICATION.