jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
543 stars 68 forks source link

question: correct way to stop/start player? #181

Closed steeley closed 2 years ago

steeley commented 2 years ago

I can start a player( I'm just using audio) and it works fine, but cannot see how to stop. This code plays the file and prints the time, but it just keeps on playing after the sleep interval.

`import mpv import time

player = mpv.MPV() player.play('babylon.wav')

@player.property_observer('time-pos') def time_observer(_name, value): print('Now playing at {:.2f}s'.format(value))

sleep(5) player.stop() player.wait_for_playback()`

neinseg commented 2 years ago

player.pause = True pauses, player.pause = False unpauses. If you actually want to close the window use player.terminate(), but then you will have to create a new MPV() instance the next time you want to play something.

steeley commented 2 years ago

thanks, it works now. I'm just playing audio (no video) and not wanting to use a gui.

erikbr01 commented 2 years ago

The player does not have a field pause, I don't know where this is coming from. I have the same problem for video playback, but this solution does not work.