-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpris test.py
82 lines (63 loc) · 2.25 KB
/
mpris test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from mpris_server.adapters import MprisAdapter
from mpris_server.events import EventAdapter
from mpris_server.server import Server
from mpris_server import Metadata
# Assume you have a simple media player class with play, pause, stop, next, and previous methods
class SimpleMediaPlayer:
def __init__(self):
self.playing = False
def play(self):
self.playing = True
def pause(self):
self.playing = False
def stop(self):
self.playing = False
def next(self):
# Implement logic to play the next track
pass
def previous(self):
# Implement logic to play the previous track
pass
# Custom implementation of MprisAdapter
class MyAppAdapter(MprisAdapter):
# def __init__(self, player):
# self.player = player
# super().__init__()
def metadata(self) -> Metadata:
metadata = Metadata()
# Populate metadata with information about the currently playing track
# metadata['Title'] = 'Sample Track'
# metadata['Artist'] = 'Sample Artist'
# metadata['Album'] = 'Sample Album'
return metadata
# def playback_status(self) -> str:
# return 'Playing' if self.player.playing else 'Paused'
# Custom implementation of MyAppEventHandler
class MyAppEventHandler(EventAdapter):
# def __init__(self, root, player):
# self.player = player
# super().__init__(player=player, root=root)
def on_app_event(self, event: str):
# trigger DBus updates based on events in your app
if event == 'pause':
self.on_playpause()
# def on_playpause(self):
# if self.player.playing:
# self.player.pause()
# else:
# self.player.play()
# def on_stop(self):
# self.player.stop()
# def on_next(self):
# self.player.next()
# def on_previous(self):
# self.player.previous()
# Create a simple media player instance
# media_player = SimpleMediaPlayer()
# Create the MPRIS adapter and server
my_adapter = MyAppAdapter()
mpris = Server('MyMediaPlayer', adapter=my_adapter)
# Initialize app integration with MPRIS
event_handler = MyAppEventHandler(root=mpris.root, player=mpris.player)
# app.register_event_handler(event_handler)
mpris.loop()