tanguyantoine / react-native-music-control

Display and manage media controls on lock screen and notification center for iOS and Android.
https://www.npmjs.com/package/react-native-music-control
MIT License
697 stars 264 forks source link

ERROR: Attempt to invoke virtual method void... #394

Open futureinapps opened 3 years ago

futureinapps commented 3 years ago

iOS works perfectly, on Android i have an error:

"Attempt to invoke virtual method void com.tanguyantoine.react.MusicControlAudioFocusListener.requestAudioFocus() on a null object reference"

  1. Sample code (provide repo url or sample code)
componentDidMount(){
    RNMS.enableBackgroundMode(true);
    RNMS.handleAudioInterruptions(true);
    RNMS.enableControl('play', true);
    RNMS.enableControl('pause', false);
    RNMS.on(Command.play, () => {
      start();
    });
    RNMS.on(Command.pause, () => {
      pause();
    });
}

if I comment RNMS.handleAudioInterruptions(true); it works perfectly, but crashes on this:

RNMS.setNowPlaying({
title: 'title',
artist: 'artist',
genre: 'genre',
// });
  1. Platform ?

    • [ ] iOS
    • [x] Android
3. Device - [ ] Simulator - [x] Real device
cjhines commented 2 years ago

Setting handleAudioInterruptions to false stopped this error for me.

Not ideal I know.

Aleksandern commented 2 years ago

I have the same issue.

@cjhines @futureinapps Did you find any other solution except setting handleAudioInterruptions to false?

cjhines commented 2 years ago

@Aleksandern

I'm afraid I eventually ended up incorporating and modifying the native modules directly into my app.