diff --git a/README.md b/README.md index 3466fb4..779b18a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ Make sure this wrapper script is only readable by you, with something like `chmo ## Limitations -mpd-now-playable is currently *very* specific to MacOS. I did my best to keep the generic MPD and extremely Apple parts separate, but it definitely won't work with MPRIS2 or the Windows system media feature. +Currently mpd-now-playable does not support seeking through the current track, because I didn't personally feel the need for that feature. It explicitly tells MacOS that seeking isn't supported by this media player, but for some reason the Mac UI still lets the user seek anyway, which of course does nothing. + +Also, mpd-now-playable is currently *very* specific to MacOS. I did my best to keep the generic MPD and extremely Apple parts separate, but it definitely won't work with MPRIS2 or the Windows system media feature. Chances are my MacOS integration code isn't the best, either. This is the first project I've written using PyObjC and it took a lot of fiddling to get working. diff --git a/src/mpd_now_playable/cocoa/now_playing.py b/src/mpd_now_playable/cocoa/now_playing.py index 19665f6..9094345 100644 --- a/src/mpd_now_playable/cocoa/now_playing.py +++ b/src/mpd_now_playable/cocoa/now_playing.py @@ -4,7 +4,6 @@ from pathlib import Path from AppKit import NSCompositingOperationCopy, NSImage, NSMakeRect from Foundation import CGSize, NSMutableDictionary from MediaPlayer import ( - MPChangePlaybackPositionCommandEvent, MPMediaItemArtwork, MPMediaItemPropertyAlbumTitle, MPMediaItemPropertyAlbumTrackNumber, @@ -32,7 +31,6 @@ from MediaPlayer import ( MPRemoteCommandCenter, MPRemoteCommandEvent, MPRemoteCommandHandlerStatus, - MPRemoteCommandHandlerStatusSuccess, ) from ..async_tools import run_background_task @@ -140,17 +138,13 @@ class CocoaNowPlaying: cmd.removeTarget_(None) cmd.addTargetWithHandler_(self._create_handler(handler)) - seekCmd = self.cmd_center.changePlaybackPositionCommand() - seekCmd.setEnabled_(True) - seekCmd.removeTarget_(None) - seekCmd.addTargetWithHandler_(self._create_seek_handler(player.on_seek)) - unsupported_cmds = ( self.cmd_center.changePlaybackRateCommand(), self.cmd_center.seekBackwardCommand(), self.cmd_center.skipBackwardCommand(), self.cmd_center.seekForwardCommand(), self.cmd_center.skipForwardCommand(), + self.cmd_center.changePlaybackPositionCommand(), ) for cmd in unsupported_cmds: cmd.setEnabled_(False) @@ -181,14 +175,3 @@ class CocoaNowPlaying: return 0 return handler - - def _create_seek_handler( - self, player: Callable[[float], Coroutine[None, None, None]] - ) -> Callable[[MPChangePlaybackPositionCommandEvent], MPRemoteCommandHandlerStatus]: - def handler( - event: MPChangePlaybackPositionCommandEvent, - ) -> MPRemoteCommandHandlerStatus: - run_background_task(player(event.positionTime())) - return MPRemoteCommandHandlerStatusSuccess - - return handler diff --git a/src/mpd_now_playable/mpd/listener.py b/src/mpd_now_playable/mpd/listener.py index ffd8a61..11f271a 100644 --- a/src/mpd_now_playable/mpd/listener.py +++ b/src/mpd_now_playable/mpd/listener.py @@ -126,6 +126,3 @@ class MpdStateListener(Player): async def on_prev(self) -> None: await self.client.previous() - - async def on_seek(self, position: float) -> None: - await self.client.seekcur(position) diff --git a/src/mpd_now_playable/player.py b/src/mpd_now_playable/player.py index fcadfa4..4f47e6d 100644 --- a/src/mpd_now_playable/player.py +++ b/src/mpd_now_playable/player.py @@ -21,6 +21,3 @@ class Player(Protocol): async def on_prev(self) -> None: ... - - async def on_seek(self, position: float) -> None: - ... diff --git a/stubs/MediaPlayer/__init__.pyi b/stubs/MediaPlayer/__init__.pyi index 01682fe..2e3b7e0 100644 --- a/stubs/MediaPlayer/__init__.pyi +++ b/stubs/MediaPlayer/__init__.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable -from typing import Final, Literal, override +from typing import Final, Literal from AppKit import NSImage from Foundation import CGSize, NSMutableDictionary @@ -52,34 +52,18 @@ class MPNowPlayingInfoCenter: def setNowPlayingInfo_(self, info: NSMutableDictionary) -> None: ... def setPlaybackState_(self, state: MPMusicPlaybackState) -> None: ... -MPRemoteCommandHandlerStatusSuccess: Final = 0 -MPRemoteCommandHandlerStatusCommandFailed: Final = 200 +MPRemoteCommandHandlerStatusSuccess: Literal[0] = 0 +MPRemoteCommandHandlerStatusCommandFailed: Literal[200] = 200 MPRemoteCommandHandlerStatus = Literal[0, 200] class MPRemoteCommandEvent: pass -class MPChangePlaybackPositionCommandEvent(MPRemoteCommandEvent): - def positionTime(self) -> float: - """Return the requested playback position as a number of seconds (fractional seconds are allowed).""" - pass - class MPRemoteCommand: def setEnabled_(self, enabled: bool) -> None: ... def removeTarget_(self, target: object) -> None: ... def addTargetWithHandler_( self, handler: Callable[[MPRemoteCommandEvent], MPRemoteCommandHandlerStatus] - ) -> None: - """Register a callback to handle the commands. Many remote commands don't carry useful information in the event object (play, pause, next track, etc.), so the callback does not necessarily need to care about the event argument.""" - pass - -class MPChangePlaybackPositionCommand(MPRemoteCommand): - @override - def addTargetWithHandler_( - self, - handler: Callable[ - [MPChangePlaybackPositionCommandEvent], MPRemoteCommandHandlerStatus - ], ) -> None: ... class MPRemoteCommandCenter: @@ -96,4 +80,4 @@ class MPRemoteCommandCenter: def skipBackwardCommand(self) -> MPRemoteCommand: ... def seekForwardCommand(self) -> MPRemoteCommand: ... def skipForwardCommand(self) -> MPRemoteCommand: ... - def changePlaybackPositionCommand(self) -> MPChangePlaybackPositionCommand: ... + def changePlaybackPositionCommand(self) -> MPRemoteCommand: ... diff --git a/stubs/mpd/asyncio.pyi b/stubs/mpd/asyncio.pyi index 221fcf4..ea29554 100644 --- a/stubs/mpd/asyncio.pyi +++ b/stubs/mpd/asyncio.pyi @@ -5,22 +5,19 @@ from mpd.base import MPDClientBase from mpd_now_playable.mpd import types class MPDClient(MPDClientBase): - mpd_version: str | None + mpd_version: str | None - def __init__(self) -> None: ... - async def connect(self, host: str, port: int = ...) -> None: ... - async def password(self, password: str) -> None: ... - def idle(self, subsystems: Sequence[str] = ...) -> AsyncIterator[Sequence[str]]: ... - async def status(self) -> types.StatusResponse: ... - async def currentsong(self) -> types.CurrentSongResponse: ... - async def readpicture(self, uri: str) -> types.ReadPictureResponse: ... - async def play(self) -> None: ... - async def pause(self, pause: Literal[1, 0, None] = None) -> None: - """Pause MPD or toggle its play/pause state. Pass pause=1 to unconditionally pause, pause=0 to unconditionally unpause, or pause=None to toggle.""" - pass - async def stop(self) -> None: ... - async def next(self) -> None: ... # noqa: A003 - async def previous(self) -> None: ... - async def seekcur(self, position: float) -> None: - """Seek to a particular time in the currently playing song, measured in seconds. Fractional seconds are supported.""" - pass + def __init__(self) -> None: ... + async def connect(self, host: str, port: int = ...) -> None: ... + async def password(self, password: str) -> None: ... + def idle(self, subsystems: Sequence[str] = ...) -> AsyncIterator[Sequence[str]]: ... + + async def status(self) -> types.StatusResponse: ... + async def currentsong(self) -> types.CurrentSongResponse: ... + async def readpicture(self, uri: str) -> types.ReadPictureResponse: ... + + async def play(self) -> None: ... + async def pause(self, pause: Literal[1, 0, None] = None) -> None: ... + async def stop(self) -> None: ... + async def next(self) -> None: ... # noqa: A003 + async def previous(self) -> None: ...