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

wait_for_playback doesn't release #161

Closed wcarman1 closed 3 years ago

wcarman1 commented 3 years ago

I'm trying to get python to run a folder as a playlist like mpv does in bash. I slightly modified the example from the readme page for playlist handling to pull local files instead of youtube. Here is what I have:

#!/usr/bin/env python3
import mpv

player = mpv.MPV(log_handler=print, loglevel='debug', input_default_bindings=True, input_vo_keyboard=True)

player.playlist_append('/home/user/Videos/a.avi')
player.playlist_append('/home/user/Videos/b.avi')
player.fullscreen = True
player.playlist_pos = 0

while True:
    # To modify the playlist, use player.playlist_{append,clear,move,remove}. player.playlist is read-only
    player.wait_for_playback()

It plays through the playlist fine but then loops at player.wait_for_playback() and never exits the script after the playlist is over. when I run player.play(xxxx) on the individual files it exits after playback is complete.

I know this is probably difficult because between each video in the playlist it sends a return status but figured I'd ask anyway.

All I want to do is run the script and play everything in the /home/user/Videos/ directory as a playlist and then exit the script gracefully but it keeps looping on the player.wait_for_playback() and doesn't return after playback is complete.

Here's my log output from running this script. https://pastebin.com/7uFzAK0G

neinseg commented 3 years ago

Because you call wait_for_playback in an infinite loop, your script does the following:

To wait for the end of the playlist in one call, you can call wait_for_property on the idle-active property, doc here.

#!/usr/bin/env python3
import mpv

player = mpv.MPV(log_handler=print, loglevel='debug', input_default_bindings=True, input_vo_keyboard=True)

player.playlist_append('/home/user/Videos/a.avi')
player.playlist_append('/home/user/Videos/b.avi')
player.fullscreen = True
player.playlist_pos = 0
player.wait_for_property('idle-active')
wcarman1 commented 3 years ago

That was exactly what I was looking for. Thank you very much! I knew it was going to be something easy .