tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] mediaSession missing on Linux

Open oofdere opened this issue 2 years ago • 11 comments

Describe the problem

I've implemented an audio player and would like the ability for it to use the Media Session API in Tauri much like in the browser so the user can view and control their media using the system notification/lock screen UIs.

Describe the solution you'd like

I would like for Tauri to support the Media Session API, or similar, ideally on mobile and desktop.

Alternatives considered

A Rust package that does the same thing, but I haven't been able to find any packages that do this, especially cross-platform.

Additional context

Related links:

  • https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API
  • https://web.dev/media-session/
  • https://www.w3.org/TR/mediasession/

oofdere avatar May 09 '23 08:05 oofdere

What OS + version are you on? Looking at the feature matrix on mdn it seems like it should work on Windows, macOS 12+, and with macOS working, Linux should work too.

FabianLars avatar May 09 '23 09:05 FabianLars

I'm using Arch Linux with tauri = { version = "1.2.4", features = [] }. Attempting to use the API results in the following error:

Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'navigator.mediaSession.playbackState = $state.paused ? "paused" : "playing"')

navigator.mediaSession isn't available on the devtools console either: image

oofdere avatar May 09 '23 18:05 oofdere

You may need webkit2gtk 2.38 to get mediaSession. Here's the release note about it set by default there: https://webkitgtk.org/2022/09/16/webkitgtk2.38.0-released.html

wusyong avatar May 10 '23 13:05 wusyong

You may need webkit2gtk 2.38 to get mediaSession. Here's the release note about it set by default there: https://webkitgtk.org/2022/09/16/webkitgtk2.38.0-released.html

I've got version 2.40 installed: https://archlinux.org/packages/extra/x86_64/webkit2gtk/

oofdere avatar May 10 '23 23:05 oofdere

Tested on macOS 13 and mediaSession does indeed work fine, so this seems to be a Linux bug. I can't test on Windows or mobile devices though.

A bit more imformation that might be relevant:

Operating System: Arch Linux KDE Plasma Version: 5.27.5 KDE Frameworks Version: 5.105.0 Qt Version: 5.15.9 Kernel Version: 6.3.1-arch1-1 (64-bit) Graphics Platform: Wayland

I've also got Pipewire installed if that matters. Happy to provide any additional info.

oofdere avatar May 11 '23 06:05 oofdere

Looks like it got disabled again because some trouble couldn't resolve. See comment 10 of this ticket in Webkit bugzilla: https://bugs.webkit.org/show_bug.cgi?id=247527#c10

wusyong avatar May 11 '23 13:05 wusyong

what's the status for windows? notification action buttons?

chiqors avatar Jun 04 '23 13:06 chiqors

@chiqors As far as we know the mediasession api works fine on Windows. If you have any problems with it, please open a separate issue.

FabianLars avatar Jun 04 '23 14:06 FabianLars

I think, wrapping the navigator.mediaSession code within feature detection and fallback logic would be a workaround it.

if ('mediaSession' in navigator) {
  navigator.mediaSession.playbackState = $state.paused ? "paused" : "playing";
} else {
  // Alternative code or fallback behavior for platforms without mediaSession support
  console.log("MediaSession API is not supported on this platform.");
}

startup-stack-sculptor avatar Jun 18 '23 07:06 startup-stack-sculptor

what's the status for windows? notification action buttons?

I can confirm that Media Session API does work on Windows 10 with WebView2.

image

abcdefghijorngarbosaxyz avatar Jun 21 '23 21:06 abcdefghijorngarbosaxyz

what's the status for windows? notification action buttons?

I can confirm that Media Session API does work on Windows 10 with WebView2.

image

Thanks for reporting it. I couldn't have a time to test it

chiqors avatar Jun 22 '23 08:06 chiqors

any update on linux webkit to open usb web camera

learncodingforweb avatar Jul 12 '23 18:07 learncodingforweb

I've re-enabled MediaSession by default (https://github.com/WebKit/WebKit/commit/32334c785916504b99c6ecbd740052a73b86f3e0). Now it's just a waiting game.

Serial-ATA avatar Apr 01 '24 17:04 Serial-ATA