python-mpv-jsonipc icon indicating copy to clipboard operation
python-mpv-jsonipc copied to clipboard

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

Open TingTingin opened this issue 2 years ago • 2 comments

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 avatar Jun 29 '22 05:06 TingTingin

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

TingTingin avatar Jun 29 '22 13:06 TingTingin

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)

chapmanjacobd avatar Oct 04 '23 04:10 chapmanjacobd