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.2k stars 984 forks source link

[Android 14] Crash on start playing the music ( audio stream ) #2143

Closed AptypTheKing closed 9 months ago

AptypTheKing commented 10 months ago

Describe the Bug When start playing the file, the app is crashing. This happened only Android 14. No logs in console, but the log in the logcat in Android Studio shows:

FATAL EXCEPTION: main
Process: **projectName**, PID: 3061
 java.lang.SecurityException: **projectName**: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.startOrUpdateNotification(PlayerNotificationManager.java:1165)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.handleMessage(PlayerNotificationManager.java:1415)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.$r8$lambda$hDN6RMWHvTCSAt_reWH1_HHmp5E(Unknown Source:0)
at com.google.android.exoplayer2.ui.PlayerNotificationManager$$ExternalSyntheticLambda0.handleMessage(Unknown Source:2)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13908)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720)
at android.os.Binder.execTransactInternal(Binder.java:1339)
at android.os.Binder.execTransact(Binder.java:1275)

The playing audio appears in notification center, but nothing is playing cause the app is crashed. Looks like somewhere receiver export is missing, but cannot find where.

Steps To Reproduce Normal setup on Android 14

Code To Reproduce

Replicable on Example App? Can you replicate this bug in the React Native Track Player Example App?

Didn't try.

Environment Info: Paste the results of npx react-native info Paste the exact react-native-track-player version you are using Real device? Or simulator? What OS are you running?

System: OS: macOS 13.0 CPU: (12) arm64 Apple M2 Pro Memory: 115.80 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.20.0 - /opt/homebrew/opt/node@16/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.19.4 - /opt/homebrew/opt/node@16/bin/npm Watchman: 2023.03.27.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/mainuser/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2022.2 AI-222.4459.24.2221.9862592 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.18 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.13 => 0.71.13 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

react-native-player version 3.2.0

Simulator Android Pixel 6 Api 34

How I can Help

Have you investigated the underlying JS or Swift/Android code causing this bug?

Looks like there is a problem with exoplayer2.

Notification notification = builder.build();
    notificationManager.notify(notificationId, notification);
    if (!isNotificationStarted) {
      context.registerReceiver(notificationBroadcastReceiver, intentFilter);
    }

I think in this function should be context.RECEIVER_EXPORTED, but it's read-only

jspizziri commented 9 months ago

@AptypTheKing please test this in the latest v4 RC. if it's still happening there I'll reopen.

ARSSHEIKH commented 9 months ago

@AptypTheKing please test this in the latest v4 RC. if it's still happening there I'll reopen.

Yes it is still happening

AptypTheKing commented 9 months ago

Will test in the nearest future

AptypTheKing commented 9 months ago

For me solved on last RC version

raymondjacobson commented 6 months ago

Hi all. What change fixed this issue?

AptypTheKing commented 6 months ago

@raymondjacobson update to the latest version

raymondjacobson commented 6 months ago

@AptypTheKing I am trying - but am seeing major issues that prevent a smooth upgrade from v3.2.0. Repeat no longer fires an event, etc. Is it possible to let me know what commit fixed this particular crash?

AptypTheKing commented 6 months ago

@raymondjacobson new version is better then old one. I strongly advice you to update. But if you really don't want, check the code and receivers export.

raymondjacobson commented 6 months ago

@raymondjacobson new version is better then old one. I strongly advice you to update. But if you really don't want, check the code and receivers export.

Is it this change? https://github.com/doublesymmetry/react-native-track-player/pull/2174/files

When trying to upgrade to v4--

Number 6 here https://rntp.dev/docs/v4-migration#general-deprecations

Event.PlaybackTrackChanged - Please use [Event.PlaybackActiveTrackChanged](https://rntp.dev/docs/api/events#playbackactivetrackchanged). Also note that in 4.0 Event.PlaybackTrackChanged is no longer emitted when a track repeats.

It seems that if repeat mode is set, no event from useTrackPlayerEvents is fired at all when the active track ends. Is this a known bug?

mayank-paryani commented 4 months ago

Hi @raymondjacobson @AptypTheKing Did you found anything to fix this Android 14 Crash?

I am currently using Track Player version 3.2.0, and I prefer not to upgrade to the latest version due to the extensive changes required for migration.

Have you discovered any manual adjustments that can be made to resolve this issue? Your assistance would be greatly appreciated.

AptypTheKing commented 3 months ago

@mayank-paryani Hi, I don't have this crash since upgraded to the latest version. I also recommend you to upgrade if you don't have so much problems with dependencies.

mayank-paryani commented 3 months ago

@mayank-paryani Hi, I don't have this crash since upgraded to the latest version. I also recommend you to upgrade if you don't have so much problems with dependencies.

@AptypTheKing Thank you for your assistance. I've successfully upgraded to version 4.0.1, resolving the crash issue on Android 14. However, I encountered an issue with the TrackPlayer.reset() method post-upgrade. In certain instances, this method caused crashes on Android devices, prompting me to remove it from certain areas.