Compare commits

..

No commits in common. "06d96314450dacdb3723c04e0078e2193158d766" and "04a976f6f3f9f30e152575d2e40f680c4ae29b63" have entirely different histories.

6 changed files with 23 additions and 63 deletions

View file

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

View file

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

View file

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

View file

@ -21,6 +21,3 @@ class Player(Protocol):
async def on_prev(self) -> None:
...
async def on_seek(self, position: float) -> None:
...

View file

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

View file

@ -11,16 +11,13 @@ class MPDClient(MPDClientBase):
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 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: ...
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