aboutsummaryrefslogtreecommitdiffstats
path: root/player_vlc.py
blob: 283102ea51eebae8576d90411971c78de96518c5 (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
import vlc

class Player:
    def __init__(self):
        self._player = vlc.MediaPlayer()

    def play(self):
        self._player.play()

    def stop(self):
        self._player.stop()

    def pause(self):
        self._player.pause()

    def isPlaying(self):
        playing = self._player.is_playing() == 1
        return playing

    def setPlaybackRate(self, rate):
        self._player.set_rate(rate)

    def getPlaybackRate(self):
        return self._player.get_rate()

    def setPlaybackPosition(self, position):
        self._player.set_position(position)

    def getPlaybackPosition(self):
        return self._player.get_position()

    def setPlaybackVolume(self, volume):
        self._player.audio_set_volume(int(volume * 100))

    def getPlaybackVolume(self):
        return self._player.audio_get_volume() / 100.0

    def setCurrentSong(self, path):
        self._player.stop()
        media = vlc.Media(path)
        self._player.set_media(media)

    def setPlayingStateChangedCallback(self, callback):
        events = [
            vlc.EventType.MediaPlayerStopped,
            vlc.EventType.MediaPlayerPlaying,
            vlc.EventType.MediaPlayerPaused
        ]
        manager = self._player.event_manager()
        for e in events:
            manager.event_attach(e, callback)

    def setPlaybackVolumeChangedCallback(self, callback):
        manager = self._player.event_manager()
        manager.event_attach(vlc.EventType.MediaPlayerAudioVolume, callback)