jofr / capacitor-media-session

Capacitor plugin for media notifications and platform media keys as well as background audio playback.
GNU General Public License v3.0
33 stars 25 forks source link

Playback screen on the lockscreen does not go away #16

Open webmasterab opened 1 year ago

webmasterab commented 1 year ago

If I set the playbackstate to none, the screen doesn't go away.

lockscreen

I don't get this 'none' via a listener but via the setting of this.playbackStopped = true;

And then calling this.updatePlaybackState(); This is the const converted to a function to use it that way.

Otherwise I don't even get the 'none' on the playBackstate

webmasterab commented 1 year ago

Looks like I haven't processed it properly yet.

Because when I test it now, the screen is gone.

Please test on real device

webmasterab commented 1 year ago

Unfortunately it does not work on a real device.

When I stop the player it stays on the lock screen.

No idea how I can fix this

jofr commented 7 months ago

Is this still a problem? And is it a problem using a native Android app or using a web app on Android?

jeremymouton commented 3 weeks ago

What does your implementation look like? Wrapping setPlaybackState in an async/await fixed the issue for me.

webmasterab commented 3 weeks ago

setPlaybackStatein

This is how I got this part.

updatePlaybackState() {

const playbackState = this.playbackStopped ? 'none' : (this.audio.paused ? 'paused' : 'playing');
MediaSession.setPlaybackState({
  playbackState: playbackState
});

}

jeremymouton commented 3 weeks ago

Try wrapping it in async/await, something like this:

async updatePlaybackState() {
  const playbackState = this.playbackStopped ? 'none' : (this.audio.paused ? 'paused' : 'playing');
  await MediaSession.setPlaybackState({
    playbackState: playbackState
  });
}