Skip to main content

▶️ Add MPRIS Integration to Media Players

mpris_server provides adapters to integrate MPRIS support in your media player or device.

Whereas existing MPRIS libraries for Python implement clients for apps with existing MPRIS support, mpris_server is a library to implement MPRIS support in apps that don't already have it. If you want to give your media player an MPRIS interface, mpris_server is right for you.

mpris_server is a fork of Mopidy-MPRIS that was extended and made into a general purpose library.

Check out 📺chromecast_mpris for an app that uses mpris_server.

Features

Implements the following from the MPRIS specification:

  • MediaPlayer2
  • MediaPlayer2.Player
  • MediaPlayer2.Playlist
  • MediaPlayer2.TrackList

The library also provides an event handler that emits org.freedesktop.DBus.Properties.PropertiesChanged in response to changes in your media player. This allows for real-time updates from your media player to DBus.

Installation

Requirements

Installing PyGObject

On Debian-derived distributions like Ubuntu, install python3-gi with apt. On Arch, you'll want to install python-gobject. On macOS, install pygobject3 via brew.

Use pip to install PyGObject>=3.34.0 if there are no installation candidates available in your vendor's package repositories.

PyPI

pip3 install mpris_server

Github

Clone the repo, run pip3 install -r requirements.txt, followed by python3 setup.py install.

Usage

Implement adapters.MprisAdapter

Subclass adapters.MprisAdapter and implement each method.

After subclassing, pass an instance to an instance of server.Server.

Implement events.EventAdapter

Subclass adapters.EventAdapter. This interface has a good default implementation, only override its methods if your app calls for it.

If you choose to re-implement its methods, call emit_changes() with the corresponding interface and a List[str] of properties that changed.

Integrate the adapter with your application to emit changes in your media player that DBus needs to know about. For example, if the user pauses the media player, be sure to call EventAdapter.on_playpause() in the app. DBus won't know about the change otherwise.

Create the Server and Publish

Create an instance of server.Server, pass it an instance of your MprisAdapter, and call publish() to publish your media player via DBus.

mpris = Server('MyMediaPlayer', adapter=my_adapter)
mpris.publish() 

Call loop() to enter the DBus event loop, or enter the DBus event loop elsewhere in your code.

mpris.loop() 

Or:

from gi.repository import GLib

loop = GLib.MainLoop()
loop.run()

Example

from mpris_server.adapters import MprisAdapter, Track
from mpris_server.events import EventAdapter
from mpris_server.server import Server

from my_app import app  # custom app you want to integrate


class MyAppAdapter(MprisAdapter):
    # Make sure to implement all methods on MprisAdapter, not just get_current_track()
    def get_current_track(self) -> Track:
        ...
    # and so on


class MyAppEventHandler(EventAdapter):
    # EventAdapter has good default implementations for its methods.
    # Only override the default methods if it suits your app.

    def on_app_event(self, event: str):
        # trigger DBus updates based on events in your app
        if event == 'pause':
            self.on_playpause()
        ...
    # and so on

# create mpris adapter and initialize mpris server
my_adapter = MyAppAdapter()
mpris = Server('MyApp', adapter=my_adapter)

# initialize app integration with mpris
event_handler = MyAppEventHandler()
app.register_event_handler(event_handler)

# publish and serve
mpris.loop()

License

See LICENSE. Message me if you'd like to use this project with a different license.

Release files for mpris-server 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpris-server 0.2.0
File Size Uploaded
mpris_server-0.2.0.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mpris-server 0.2.0
File Interpreter ABI Platform
mpris_server-0.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.1 kB

Release files / mpris_server-0.2.0.tar.gz

Download URL mpris_server-0.2.0.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b39b5a1c93b5f15905f62deb29a09b768b56e5ca4bf81d62aaaa34e4e13dcc76
BLAKE2b-256 checksum
How to use checksums
76c600e8598be7fc0e1b37897d1c7bb8332ff5965ee5df9046e241c52b80406d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / mpris_server-0.2.0-py2.py3-none-any.whl

Download URL mpris_server-0.2.0-py2.py3-none-any.whl
Size 14.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e2a28b105d6b7cca173e64dabd5b19655a08b1582020914f7f456f8144c1216a
BLAKE2b-256 checksum
How to use checksums
f9119a9c2e96f147f3c3ab15db3a0b3ddb81ffb26ac5bcf54e90379f28430242
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

0.9.6

2 release files

0.9.5

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.14

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.5

1 release file

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.8

3 release files

0.1.7

3 release files

0.1.6

2 release files

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page