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

player.loop_playlist = 'inf' not replaying media #139

Closed jakeogh closed 3 years ago

jakeogh commented 3 years ago

Am I doing this incorrectly? The test case below only plays test.mkv a single time. I expect it to loop forever.

#!/usr/bin/env python3

import sys
import mpv

def logger(loglevel, component, message):
    print('[{}] {}: {}'.format(loglevel, component, message), file=sys.stderr)

def play(media):

    print("play('{}')".format(media), file=sys.stderr)

    player = mpv.MPV(ytdl=True,
                     log_handler=logger,
                     input_default_bindings=True,
                     input_vo_keyboard=True,
                     terminal=True,
                     input_terminal=True,
                     script_opts='osc-layout=bottombar,osc-seekbarstyle=bar',
                     osc=True)

    player.on_key_press('ESC')(player.quit)
    player.on_key_press('ENTER')(lambda: player.playlist_next(mode='force'))
    player.loop_playlist = 'inf'

    try:
        for item in media:
            player.play(item)
            player.wait_for_playback()
    except mpv.ShutdownError:
        pass

    player.terminate()

if __name__ == '__main__':
    play(media=['test.mkv'])
jaseg commented 3 years ago

In the "for" loop, your code enqueues test.mkv, then waits for it to finish, then leaves the loop and terminates the player.

wait_for_playback returns after the current playing file is done. So if you have several files in a playlist, or a looping playlist, it will return once after each entry.

jaseg commented 3 years ago

I'm closing this issue because it seems it is resolved.

jakeogh commented 2 years ago

Hey sorry for the lack of follow up, my confusion was that I want to loop test.mkv, not a playlist, setting:

player.loop_file = 'inf' instead of player.loop_playlist = 'inf'

did what I wanted. TY!

the playlist case is explained in #161