jwplayer / jwplayer-react-native

MIT License
32 stars 9 forks source link

[BUG] Enabling background audio on Android 14 or later causes a crash #53

Closed Solly74 closed 4 months ago

Solly74 commented 4 months ago

Describe the bug React Native: 0.73.4 @jwplayer/jwplayer-react-native: 1.0.1 Enabling background audio on Android 14 causes the video to crash with the following trace.

Screenshot 2024-06-26 at 12 47 07

morrieinmaas commented 4 months ago

I think you can check for/set minsdkversion in build.gradle to be >=34 and then set foreground service type in manifest.xml (https://developer.android.com/about/versions/14/changes/fgs-types-required, seems required from 34 onward)

Solly74 commented 4 months ago

@morrieinmaas is background audio a foreground service? It was my understanding it was a background service, hence the need for https://docs.jwplayer.com/players/docs/android-enable-background-audio

morrieinmaas commented 4 months ago

Hey @Solly74 - well just saw that in my emails and thought hang on a second that looks somewhat familiar. The error stack says foreground service so thought that's relevant. anyway, haven't looked at any of your code. Jus thought it might help 😄

you see that the jwplayer.backgroundservice seems to try enable a foreground service so i guess that that needs to be explicitly set in android 14. anyway, again just thought this might help.

Jmilham21 commented 4 months ago

This is resolved via this commit. The change will be in the next release (1.0.2: date TBD)

You are correct, @morrieinmaas that the service type must be specified with Android 14 and higher.

@Solly74 The background audio service has to be foreground service since it is playing audio and interacts with the main thread. See the developer docs explaining the Service types here.