iwalton3 / python-mpv-jsonipc

Python API to MPV using JSON IPC
Other
53 stars 4 forks source link

If you have multiple scripts connected to the same mpv instance they all receive keypresses #13

Open TingTingin opened 2 years ago

TingTingin commented 2 years ago

If you have multiple scripts connected to the same mpv instance they all receive keypresses https://github.com/iwalton3/python-mpv-jsonipc/blob/9b16ab8eceb46bbc519a97e4ce8e79dceaf94bcf/python_mpv_jsonipc.py#L444 changing to self.keybind = time.time_ns() could make it so that ids are more unique to avoid clashes

TingTingin commented 2 years ago

could also use uuid1().int but dont know if thats overkill

chapmanjacobd commented 11 months ago

It seems like terminating an mpv instance from a different mpv instance also has a problem. a thread stays open:

left_mpv.quit_callback = right_mpv.terminate
right_mpv.quit_callback = left_mpv.terminate

for example:

from python_mpv_jsonipc import MPV

def auto_seek(x_mpv, delay=0.0):
    x_mpv.wait_for_property('duration')
    time.sleep(delay)
    while True:
        for _ in range(20):
            x_mpv.command("seek", "0.2", "relative-percent")
            time.sleep(0.05)
        for _ in range(5):
            x_mpv.command("seek", "3", "relative-percent")
            time.sleep(1.2)

left_mpv = MPV()
right_mpv = MPV()

left_mpv.play(left_side)
right_mpv.play(right_side)

left_mpv.quit_callback = right_mpv.terminate
right_mpv.quit_callback = left_mpv.terminate

with ThreadPoolExecutor() as e:
    e.submit(auto_seek, left_mpv)
    e.submit(auto_seek, right_mpv, delay=0.4)