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

Cannot run the seek command #144

Closed Luni-4 closed 3 years ago

Luni-4 commented 3 years ago

I'm on Ubuntu 20.10 with python-mpv 0.5.2. When I try to launch this script:

import mpv

player = mpv.MPV(ytdl=False, osc=True, loglevel="info", log_handler=print)
player.seek("00:01:14.0", "absolute", "exact")
player.play('/path/to/file.mkv')
player.wait_for_playback()

I get the following error:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    player.seek("00:01:14.0", "absolute", "exact")
  File "/home/.local/lib/python3.8/site-packages/mpv.py", line 1054, in seek
    self.command('seek', amount, reference, precision)
  File "/home/.local/lib/python3.8/site-packages/mpv.py", line 1041, in command
    _mpv_command(self.handle, (c_char_p*len(args))(*args))
  File "/home/.local/lib/python3.8/site-packages/mpv.py", line 133, in raise_for_ec
    raise ex(ec, *args)
SystemError: ('Error running mpv command', -12, (<MpvHandle object at 0x7fbdef494dc0>, <mpv.c_char_p_Array_5 object at 0x7fbdef1bb4c0>))

Am I doing something wrong? Thanks in advance for your help! :)

jaseg commented 3 years ago

You can't seek before the file is loaded. As an alternative, consider passing the start option to either the MPV object or to MPV.loadfile.

Luni-4 commented 3 years ago

Yep, you're right, I inverted the lines:

import mpv

player = mpv.MPV(ytdl=False, osc=True, loglevel="info", log_handler=print)
player.play('/path/to/file.mkv')
player.seek("00:01:14.0", "absolute", "exact")
player.wait_for_playback()

but I get the same error.

Instead, the start option inside the MPV object works, but unfortunately I need the seek function

McSinyx commented 3 years ago

I think this is the duplicate of GH-79. Maybe we should have a context manager whose __enter__ waits for basic properties to initialize and __exit__ calls wait_for_playback, but I'm not sure which mpv properties should be considered as basic.

Luni-4 commented 3 years ago

Thank you @McSinyx! I tried the solution described in the duplicate issue and now it works perfectly! :)