tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
84.68k stars 2.55k forks source link

[bug] mediaSession missing on Linux #6913

Open oofdere opened 1 year ago

oofdere commented 1 year ago

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:

FabianLars commented 1 year ago

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.

oofdere commented 1 year ago

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

wusyong commented 1 year ago

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

oofdere commented 1 year ago

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 commented 1 year ago

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.

wusyong commented 1 year ago

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

chiqors commented 1 year ago

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

FabianLars commented 1 year ago

@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.

startup-stack-sculptor commented 1 year ago

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.");
}
abcdefghijorngarbosaxyz commented 1 year ago

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

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

image

chiqors commented 1 year ago

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

learncodingforweb commented 1 year ago

any update on linux webkit to open usb web camera

Serial-ATA commented 7 months ago

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