emmental/emmental/mpris2/player.py

78 lines
2.4 KiB
Python

# Copyright 2022 (c) Anna Schumaker.
"""Our Mpris2 Player dbus Object."""
import pathlib
from gi.repository import GObject
from .. import path
from . import dbus
PLAYER_XML = pathlib.Path(__file__).parent / "Player.xml"
class Player(dbus.Object):
"""The mpris2 Player dbus object."""
PlaybackStatus = GObject.Property(type=str, default="Stopped")
LoopStatus = GObject.Property(type=str, default="None")
Rate = GObject.Property(type=float, default=1.0)
Shuffle = GObject.Property(type=bool, default=False)
Volume = GObject.Property(type=float, default=1.0)
Position = GObject.Property(type=float, default=0)
MinimumRate = GObject.Property(type=float, default=1.0)
MaximumRate = GObject.Property(type=float, default=1.0)
CanGoNext = GObject.Property(type=bool, default=False)
CanGoPrevious = GObject.Property(type=bool, default=False)
CanPlay = GObject.Property(type=bool, default=False)
CanPause = GObject.Property(type=bool, default=False)
CanSeek = GObject.Property(type=bool, default=False)
CanControl = GObject.Property(type=bool, default=True)
def __init__(self):
"""Initialize the mpris2 application object."""
super().__init__(xml=PLAYER_XML)
@GObject.Property
def Metadata(self) -> dict:
"""Metadata for the current Track."""
return {}
@GObject.Signal
def Next(self) -> None:
"""Skip to the next track."""
@GObject.Signal
def Previous(self) -> None:
"""Skip to the previous track."""
@GObject.Signal
def Pause(self) -> None:
"""Pause playback."""
@GObject.Signal
def PlayPause(self) -> None:
"""Toggle playback status."""
@GObject.Signal
def Stop(self) -> None:
"""Stop playback."""
@GObject.Signal
def Play(self) -> None:
"""Start or resume playback."""
@GObject.Signal(arg_types=(float,))
def Seek(self, offset: float) -> None:
"""Seek forward or backward by the given offset."""
@GObject.Signal(arg_types=(str, float))
def SetPosition(self, trackid: str, position: float) -> None:
"""Set the current track position in microseconds."""
@GObject.Signal(arg_types=(str,))
def OpenUri(self, uri: str) -> None:
"""Open the given uri."""
self.emit("OpenPath", path.from_uri(uri))
@GObject.Signal(arg_types=(GObject.TYPE_PYOBJECT,))
def OpenPath(self, filepath: pathlib.Path) -> None:
"""Open the given path."""