| blc - Simple program for rendering QLC+ workspaces properly/without crashing. Developed into BLC2.
git clone https://benconnors.ca/git-repos/blc |
mpv.py (1274B) - raw
1 """Module for using MPV as the AudioPlayer backend.""" 2 3 import mpv 4 5 from .interface import AudioPlayer 6 from .util import titot, ttoti 7 8 class MPVPlayer(AudioPlayer): 9 """Class for using MPV as an audio player.""" 10 @property 11 def position(self): 12 return ttoti(self.player.time_pos) 13 14 def play(self, start=-1): 15 ## TODO: Raise error if already playing? 16 self.started = True 17 self.player.pause = False 18 19 def pause(self): 20 self.player.pause = True 21 22 def seek(self, t): 23 self.player.seek(titot(t), reference="absolute", precision="exact") 24 25 def stop(self): 26 self.player.pause = True 27 self.seek(0) 28 29 @property 30 def volume(self) -> int: 31 return int(self.player.volume) 32 33 @volume.setter 34 def volume(self, value): 35 self.player.volume = value 36 37 @property 38 def playing(self) -> bool: 39 return self.started and not (self.player.pause or self.player.eof_reached) 40 41 def terminate(self): 42 self.player.terminate() 43 44 def __init__(self, fname, args=()): 45 super().__init__(fname, args) 46 self.player = mpv.MPV() 47 self.player.pause = True 48 self.player.keep_open = True 49 self.started = False 50 self.player.loadfile(fname)