Closed Bug 1353652 Opened 7 years ago Closed 4 years ago

[MediaControl-Linux] Provide MPRIS API for music/video streaming web sites

Categories

(Core :: Widget: Gtk, enhancement, P3)

52 Branch
enhancement

Tracking

()

RESOLVED FIXED
mozilla75
Tracking Status
firefox75 --- fixed

People

(Reporter: dev, Assigned: MeFisto94)

References

(Depends on 2 open bugs, Blocks 1 open bug, )

Details

Attachments

(4 files)

User Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Build ID: 20170327113357




Expected results:

There should be an API for music and video streaming web sites like soundcloud/spotify/youtube/... to interact with the systems media player API like MPRIS.
So users are able to see the current playing track/video and control playback (pause, play, stop, forward, backward, ...) like they're used to do directly in their system.
Severity: normal → enhancement
Component: Untriaged → Audio/Video
Product: Firefox → Core
Component: Audio/Video → Audio/Video: Playback
Yes. I didn't know that there is such an API but it looks  like it's the right place.
I found this addon for KDE Plasma called "Plasma Integration" (https://addons.mozilla.org/firefox/addon/plasma-integration/). I somehow detects the name of the media, firefox currently plays, and integrates it into the system.

Should this be considered a duplicate or a dependency of #448910?

The other bug only covers media keys on keyboards. My intention was to integrate audio and video playback into the system in order that Firefox acts like a media player. Then other applications can for example pause playback when a phone call comes in or display the current track on SoundCloud or Spotify...

You're right, I just thought they were directly related as MPRIS can provide multimedia keyboard support from the desktop environment

I will try to work on implementing the native side of MPRIS so it can be combined with the MediaSession API when done.

Assignee: nobody → marc.streckfuss
Status: UNCONFIRMED → NEW
Ever confirmed: true

FYI, as I've implemented a MediaController interface in bug1565689, we can use it to play/pause media in firefox if we would like to control media from the system level panel.

See Also: → 1584030

So this is my first approach for a Skeleton Class to provide MPRIS Support.

Before going into the implementational details: I failed at extracting the class into it's own cpp file, for some reason other files break and namespaces get confused. So could someone maybe have a quick glance at what I did wrong, so I can compile and test everything again?

I added the file simply to the UNIFIED_SOURCES in alphabetical order:

    'mozcontainer.cpp',
    'MPRISServiceHandler.cpp',
    'NativeKeyBindings.cpp',

The file sometimes had the namespace ::mozilla::widget::mozila::widget amongst other things, while working fine as part of WindowServiceProvider. I am sorry for that inconvenience.

The following problems need consideration:

  1. Multithreading. The Run() method will block the calling thread and all received events will be delivered from that Thread. This means that method calls/Events like Stop() and Seek() will come from the D-Bus Thread and changing Properties like the Metadata coming from a different thread has to be synchronized.
  2. Note: The Parts guarded with defines are not yet implemented but are also optional
  3. https://specifications.freedesktop.org/mpris-spec/2.2/Track_List_Interface.html and https://specifications.freedesktop.org/mpris-spec/2.2/Playlists_Interface.html haven't been implemented, they are optional as well and only rarely make sense for Firefox, especially given that the MediaSession API is (not yet) advanced enough.
  4. The API is not generic enough in two ways:
    4.1 struct MPRISMetadata is difficult: I have to pass the Metadata as array of GVariant *, because the length of a track and the cd-number might well be an integer, where the artist certainly is a string. There are too much possible tags available, but:
    4.2 The whole API might need to be adjusted to what can be supported with the Media Session API and maybe what other platforms (Mac OS and Windows) offer. Ideally the OS-dependant Implementation can be switched out without the caller knowing. This would however mean we indeed need to translate metadata. If we wanted to support all media playing (like directly playing mp3 files) though, then we would limit ourselves too much when only allowing what the Media Session API specifies.
  5. Binding of the Code to other parts: Obviously one wants to register Handlers for all the Events and Properties.
  6. Feel free to try the code already. All that you need to do is get the class to compile again and invoke Initialize() and Run(), then you will see Mozilla Firefox Nightly appearing as Media Player in your system tray with some dummy values filled in and some printf() when you trigger events.

I think that is all for now, I'd love to hear some feedback

Flags: needinfo?(drno)
Status: NEW → ASSIGNED
Depends on: 1591288
No longer depends on: 1591288
No longer blocks: webext-commands-global
Component: Audio/Video: Playback → Widget: Gtk
Summary: Provide MPRIS API for music/video streaming web sites → [MediaControl-Linux] Provide MPRIS API for music/video streaming web sites

Hi, Martin,

I heard that you might be a best person to ask for the question about gnome, could you give us some suggestion on [1]?
Thank you!

[1] https://phabricator.services.mozilla.com/D47999#1655569

Flags: needinfo?(stransky)

I forwarded the question to Jean Felder. But it looks to me that pure MPRIS is a way to go, see this recent gnome-shell extension for instance:
https://github.com/JasonLG1979/gnome-shell-extension-mpris-indicator-button

and how it uses the MPRIS:
https://github.com/JasonLG1979/gnome-shell-extension-mpris-indicator-button/blob/master/mprisindicatorbutton%40JasonLG1979.github.io/dbus.js

Flags: needinfo?(stransky)
Attachment #9098415 - Attachment description: Bug 1353652 - Initial Draft of MPRIS API Provider (Media API on Linux) → Bug 1353652 - Fix unified builds
Attachment #9098415 - Attachment description: Bug 1353652 - Fix unified builds → Bug 1353652 - Initial Draft of MPRIS API Provider (Media API on Linux)

(In reply to Martin Stránský [:stransky] from comment #15)

I forwarded the question to Jean Felder. But it looks to me that pure MPRIS is a way to go, see this recent gnome-shell extension for instance:
https://github.com/JasonLG1979/gnome-shell-extension-mpris-indicator-button

Guys,

there's a reply from Jean Felder. From my understanding it's OK to use only MPRIS and
don't care about GNOME media keys.


Regarding GNOME Media keys and MPRIS:

GNOME settings daemon is able to detect the media key events and send this
information to the registered applications with its own api [1].
However, it also acts as an MPRIS controller. So, if an application has
MPRIS support it will use MPRIS instead of the media-keys API.
See the relevant part of the code [2] and the initial bug report [3].

To sum it up:

  • (if) you don't have MPRIS support in you application and you want to handle
    the media keys: use the media-keys-API [1]
  • (if) you have MPRIS support in your application: you don't need the media-keys
    API. The media keys events are handled by MPRIS (via the MediaPlayer.Player
    interface [4]).

[1]
https://gitlab.gnome.org/GNOME/gnome-settings-daemon/blob/master/plugins/media-keys/README.media-keys-API
[2]
https://gitlab.gnome.org/GNOME/gnome-settings-daemon/blob/master/plugins/media-keys/gsd-media-keys-manager.c#L1845
[3] https://bugzilla.gnome.org/show_bug.cgi?id=697810
[4]
https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html


Depends on: 1601508
Keywords: leave-open

== Change summary for alert #24249 (as of Wed, 04 Dec 2019 11:10:27 GMT) ==

Improvements:

24% build times linux64 tsan taskcluster-m5.4xlarge tsan-fuzzing 1,475.89 -> 1,128.68

For up to date results, see: https://treeherder.mozilla.org/perf.html#/alerts?id=24249

Depends on: 1603527
Depends on: 1603544

I'm not familiar with Bugzilla or Phabricator but it looks like the suggested code set the mpris:artUrl to the icon of Firefox?

Should this be set to the artwork defined in the Media Session API? Also see the spec:
https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata/#mpris:arturl

This is what other clients on Linux like Spotify or Auryo do.

Depends on: 1604653
Depends on: 1611235
Pushed by marc.streckfuss@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/b4dc366c9161
Initial Draft of MPRIS API Provider (Media API on Linux) r=alwu
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla75
Pushed by marc.streckfuss@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/e7e12a4881b8
Initial Draft of MPRIS API Provider (Media API on Linux) r=alwu
Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla75
Flags: needinfo?(marc.streckfuss)
Depends on: 1615375

This doesn't actually use the metadata from navigator.mediaSession, does it? Is this planned to be implemented?

See the tracking bug here: https://bugzilla.mozilla.org/show_bug.cgi?id=1572869
First we will add the Favicon and Tab Title as Metadata and then we will have support for Media Session, but currently there is no Metadata at all.
We do it step by step and also want to support sites not using MediaSession API anyway :)

I see. Thanks a lot, going to follow the tracking bug. Also not sure if this should go here or there: the way Firefox currently interacts directly with the <audio>/<video> element seems to break some React websites for me that do their own state tracking.

I guess the best would be to report this as a blocking bug to the media-control meta bug providing more detailed information (e.g. an example page and maybe even how the state can break).

This is specifically interesting because for the websites it shouldn't be different than a manual click, really, so it probably is some side-effect.

(In reply to Ilya K from comment #31)

I see. Thanks a lot, going to follow the tracking bug. Also not sure if this should go here or there: the way Firefox currently interacts directly with the <audio>/<video> element seems to break some React websites for me that do their own state tracking.

According to what we got on Fennec before (we have enabled media control on Android for a long while), if the web media player doesn't listen to play and pause event properly and only rely on touch event on their interface, then it's high chance to have a inconsistency on their interface when we control media element directrly by media control.

But free feel to open a new bug for that, and NI me on that bug.

Thank you.

Flags: needinfo?(drno)

Yep, that's basically the issue. I've checked on Fennec/Fenix, and it's the same thing there. I guess there's no reason to open a bug then.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: