Skip to content

Commit

Permalink
macos impl
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceZhang1993 committed Jul 1, 2024
1 parent d7f08b1 commit 041d5b1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions aionowplaying/backend/macos.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,57 @@
import asyncio
from typing import List

from Foundation import NSMutableDictionary
from MediaPlayer import MPRemoteCommandCenter, MPNowPlayingInfoCenter
from MediaPlayer import (
MPMediaItemPropertyTitle, MPMediaItemPropertyArtist, MPMediaItemPropertyAlbumTitle,
MPMusicPlaybackStatePlaying, MPMusicPlaybackStatePaused,
MPMusicPlaybackStateStopped, MPMediaItemPropertyPlaybackDuration,
MPNowPlayingInfoPropertyPlaybackRate, MPNowPlayingInfoPropertyElapsedPlaybackTime,
MPRemoteCommandHandlerStatusSuccess, MPNowPlayingInfoPropertyDefaultPlaybackRate,
)

from aionowplaying.enum import PlaybackStatus
from aionowplaying.interface import MPInterface, MPPlayerInterface, MPTrackListInterface

PlaybackStatusStateMapping = {
PlaybackStatus.Playing: MPMusicPlaybackStatePlaying,
PlaybackStatus.Paused: MPMusicPlaybackStatePaused,
PlaybackStatus.Stopped: MPMusicPlaybackStateStopped,
}

from aionowplaying.backend import BaseNowPlayingBackend


def create_handler(_, handler):
def handle(_):
asyncio.create_task(handler())
return MPRemoteCommandHandlerStatusSuccess

return handle


class MacOSNowPlayingBackend(BaseNowPlayingBackend):
@staticmethod
def target_platforms() -> List[str]:
return ['darwin']

def __init__(self, interface: MPInterface, player_interface: MPPlayerInterface,
tracklist_interface: MPTrackListInterface):
super().__init__(interface, player_interface, tracklist_interface)
self.cmd_center = MPRemoteCommandCenter.sharedCommandCenter()
self.info_center = MPNowPlayingInfoCenter.defaultCenter()

self._cmds = [
(self.cmd_center.togglePlayPauseCommand(), self._player_interface.playPause),
(self.cmd_center.playCommand(), self._player_interface.play),
(self.cmd_center.pauseCommand(), self._player_interface.pause),
(self.cmd_center.nextTrackCommand(), self._player_interface.next),
(self.cmd_center.previousTrackCommand(), self._player_interface.previous),
]
for cmd, handler in self._cmds:
cmd.addTargetWithHandler_(create_handler(cmd, handler))

def run(self):
pass

Expand Down

0 comments on commit 041d5b1

Please sign in to comment.