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

ios controls persist after calling `MusicControl.stopControl` #376

Closed PupoSDC closed 2 years ago

PupoSDC commented 3 years ago

Description

I'm calling MusicControl.stopControl() on the clean up fuction of useEffect:


 useEffect(() => () => {
   MusicControl.stopControl();
 });

but the player persists after this call.

Before the callback:

image

after the callback:

image

  1. Platform ?

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

I dug quite bit into the code and

RCT_EXPORT_METHOD(resetNowPlaying)
{
    MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
    center.nowPlayingInfo = nil;
    self.artworkUrl = nil;
}

appears to be working as intended. center.nowPlayingInfo = nil is set correctly, which according to the docs should be sufficient to make the controls disappear:

https://developer.apple.com/documentation/mediaplayer/mpnowplayinginfocenter/1615903-nowplayinginfo

PupoSDC commented 3 years ago

So in the end the answer was hidden in a somewhat cryptic post from 2018:

https://github.com/tanguyantoine/react-native-music-control/issues/135#issuecomment-396554383

You have to change the state of the controls to STOPPED before closing the controls, otherwise they will not close!

      MusicControl.updatePlayback({
        state: MusicControl.STATE_STOPPED,
        elapsedTime: 0,
      });
      MusicControl.stopControl();
leightonkuchel commented 3 years ago

So in the end the answer was hidden in a somewhat cryptic post from 2018:

#135 (comment)

You have to change the state of the controls to STOPPED before closing the controls, otherwise they will not close!

      MusicControl.updatePlayback({
        state: MusicControl.STATE_STOPPED,
        elapsedTime: 0,
      });
      MusicControl.stopControl();

Hmm even when setting it's state (literally copy/paste yours) I can't get it to hide the controls 🤔

bradfloodx commented 3 years ago

@leightonkuchel How did you go with this? Is this an iOS issue? or related to our package here?

AliHaidar110 commented 2 years ago

So in the end the answer was hidden in a somewhat cryptic post from 2018:

#135 (comment)

You have to change the state of the controls to STOPPED before closing the controls, otherwise they will not close!

      MusicControl.updatePlayback({
        state: MusicControl.STATE_STOPPED,
        elapsedTime: 0,
      });
      MusicControl.stopControl();

didn't work :(