capacitor-media-session icon indicating copy to clipboard operation
capacitor-media-session copied to clipboard

Playback screen on the lockscreen does not go away

Open webmasterab opened this issue 2 years ago • 6 comments

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 avatar Aug 07 '23 19:08 webmasterab

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 avatar Aug 07 '23 19:08 webmasterab

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

webmasterab avatar Aug 10 '23 08:08 webmasterab

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

jofr avatar Jan 21 '24 12:01 jofr

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

jeremymouton avatar Aug 19 '24 15:08 jeremymouton

setPlaybackStatein

This is how I got this part.

updatePlaybackState() {

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

}

webmasterab avatar Aug 19 '24 15:08 webmasterab

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
  });
}

jeremymouton avatar Aug 19 '24 15:08 jeremymouton