aboutsummaryrefslogtreecommitdiffstats
path: root/notifier.py
blob: fc91e8ce7f9ec535417f50f4edce2d1c1ed1e0fc (plain)
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
class Notifier:
    PLAYING_STATE_EVENT = 0
    PLAYBACK_VOLUME_EVENT = 1
    PLAYBACK_RATE_EVENT = 2
    CURRENT_SONG_EVENT = 3
    CURRENT_AB_EVENT = 4

    def __init__(self, player):
        self._callbacks = dict()
        self._player = player
        self._player.setPlayingStateChangedCallback(self._playingStateChangedCallback)
        self._player.setPlaybackVolumeChangedCallback(self._playbackVolumeChangedCallback)

    def registerCallback(self, event, callback):
        if event not in self._callbacks:
            self._callbacks[event] = list()
        self._callbacks[event].append(callback)

    def notify(self, event):
        for callback in self._callbacks.get(event, list()):
            callback()

    def _playingStateChangedCallback(self, *args):
        self.notify(Notifier.PLAYING_STATE_EVENT)

    def _playbackVolumeChangedCallback(self, *args):
        self.notify(Notifier.PLAYBACK_VOLUME_EVENT)