react-native-jw-media-player icon indicating copy to clipboard operation
react-native-jw-media-player copied to clipboard

[ANDROID] Disable Background Audio

Open ybbond opened this issue 4 years ago • 10 comments

Currently, background audio for android is hardcoded as in this code. https://github.com/chaimPaneth/react-native-jw-media-player/blob/da7c7d8a2c700391bd20a32aa21fd13fa0f344ae/android/src/main/java/com/appgoalz/rnjwplayer/RNJWPlayerView.java#L506

I tried hardcoding it as:

mPlayer.setBackgroundAudio(false);

But it is not working. Let's investigate whether it is JWPlayer's SDK fault or there is something more to be added for this package

ybbond avatar May 14 '20 18:05 ybbond

I have the same problem. T.T

pqv2210 avatar Jun 10 '20 02:06 pqv2210

do you tried to hardcode the java too?

My current solution is to listen for react-navigation lose focus and call player.pause() method on javascript side. not optimal solution, but maybe that helps

we will still need to investigate this tho.

ybbond avatar Jun 10 '20 09:06 ybbond

Hi @ybbond & @pqv2210 there is a pending PR https://github.com/chaimPaneth/react-native-jw-media-player/pull/68 for this issue though I didn't have time to check it yet can you confirm it works and I'll merge it.

I think though that we need to disable the audio focus and media service as well to completely disable audio background.

chaimPaneth avatar Jun 10 '20 16:06 chaimPaneth

@ybbond Yep, I hardcode too, but it wasn't working. I use AppState from react-native, listen state change and call 'current.pause()' like you. It works pretty fast. 😄

pqv2210 avatar Jun 19 '20 04:06 pqv2210

@pqv2210 yes, the performance hit is not noticable with that approach.

@chaimPaneth I might test the build from #68 later next week, got pretty busy last week.

ybbond avatar Jun 20 '20 08:06 ybbond

I added a backgroundAudioEnabled prop for this purpose in the latest version 0.1.48 but after some debugging it seems it's only working on iOS but on android it does keep playing in the background even though there is no media session or audio focus request when the backgroundAudioEnabled prop is false, though this successfully disables the notification center controls.

Might be on newer devices it does work I checked on an old Android device.

Can anyone check the latest version if this props works as intended in Android?

Thanks.

chaimPaneth avatar Jul 16 '20 07:07 chaimPaneth

@chaimPaneth So I tried setting backgroundAudioEnabled to false. In android it keeps playing without a notification controls. On iOS it does not work at all when set to true (at least on emulator).

KestasVenslauskas avatar Jul 31 '20 10:07 KestasVenslauskas

Another issue that there is no notification on Xiaomi 9T pro phone. Not sure about other xiaomi phones

KestasVenslauskas avatar Aug 04 '20 19:08 KestasVenslauskas

@chaimPaneth any update on this? I have checked it on real iOS device and the problem is that controls on notification does not work at all.

KestasVenslauskas avatar Aug 13 '20 06:08 KestasVenslauskas

I forget to inform that I did a quick check 2 weeks ago, and it works. But I think we need further check. Should we make a priority test cases?

such as with background audio disabled, will it show media drawer on notification.

ybbond avatar Aug 13 '20 08:08 ybbond

Closing due to inactivity.

chaimPaneth avatar Feb 08 '24 07:02 chaimPaneth