aboutsummaryrefslogtreecommitdiffstats
path: root/player_mock.py
blob: 3162e0fbbb7dbed013364315fcd56fae5f1c1f38 (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
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
class Player():
    STOPPED = 0
    PLAYING = 1
    PAUSED = 2

    def __init__(self):
        self.state = Player.STOPPED
        self.rate = 1.0
        self.position = 0.0
        self.volume = 1.0
        self.currentSong = None
        self.playingStateChangedCallback = None
        self.playbackVolumeChangedCallback = None

    def play(self):
        previousState = self.state
        self.state = Player.PLAYING
        if previousState != Player.PLAYING:
            self.playingStateChangedCallback()

    def stop(self):
        previousState = self.state
        self.state = Player.STOPPED
        if previousState != Player.STOPPED:
            self.playingStateChangedCallback()

    def pause(self):
        previousState = self.state
        self.state = Player.PAUSED
        if previousState != Player.PAUSED:
            self.playingStateChangedCallback()

    def isPlaying(self):
        return self.state == Player.PLAYING

    def setPlaybackRate(self, rate):
        self.rate = rate

    def getPlaybackRate(self):
        return self.rate

    def setPlaybackPosition(self, position):
        self.position = position

    def getPlaybackPosition(self):
        return self.position

    def setPlaybackVolume(self, volume):
        changed = self.volume != volume
        self.volume = volume
        if changed:
            self.playbackVolumeChangedCallback()

    def getPlaybackVolume(self):
        return self.volume

    def setCurrentSong(self, path):
        self.stop()
        self.currentSong = path

    def setPlayingStateChangedCallback(self, callback):
        self.playingStateChangedCallback = callback
    
    def simulatePlayingStateChanged(self):
        self.playingStateChangedCallback()

    def setPlaybackVolumeChangedCallback(self, callback):
        self.playbackVolumeChangedCallback = callback

    def simulatePlaybackVolumeChanged(self):
        self.playbackVolumeChangedCallback()