GithubHelp home page GithubHelp logo

Comments (4)

jaseg avatar jaseg commented on August 27, 2024

That is part of the default input bindings. You could either load the default bindings by setting input_default_bindings=True in the constructor or manually add this one particular binding.

# to have the libmpv instance "quit", but not the python interpreter
player.register_key_binding("CLOSE_WIN", "quit")
# to manually orchestrate quitting from the python side
def quit(state, key):
    if state[0] == 'd':
        player.terminate()
        sys.exit(0)
player.register_key_binding("CLOSE_WIN", quit)

from python-mpv.

stax76 avatar stax76 commented on August 27, 2024

Neither works, I have input-default-bindings=yes in my mpv.conf

import sys, mpv

player = mpv.MPV(config='yes', input_default_bindings=True)

# to have the libmpv instance "quit", but not the python interpreter
player.register_key_binding("CLOSE_WIN", "quit")
# to manually orchestrate quitting from the python side
def quit(state, key):
    if state[0] == 'd':
        player.terminate()
        sys.exit(0)
player.register_key_binding("CLOSE_WIN", quit)

if len(sys.argv) == 1:
    sys.argv = ["",
               r"D:\Temp\StaxRip\doku.mkv",
               r"D:\Temp\StaxRip\Eli.mp4",
               r"D:\Temp\StaxRip\atmos.mkv"]

for file in sys.argv[1:]:
    player.playlist_append(file)

player.playlist_pos = 0

while True:
    player.wait_for_playback()

from python-mpv.

jaseg avatar jaseg commented on August 27, 2024

So, there are a couple of problems here. First, be careful: if you register the same key binding twice, the second one will override the first one. So in the above example, only the second registration is effective. Doc here.

The function does not work due to a change in the upstream API since I wrote the doc ('d' β†’ 'p'). Besides fixing that I added a new MPV.on_key_press function decorator simplifying key bindings to python functions. This will be released as soon as I get libmpv to stop segfaulting on me.

The simple quit input command binding does not work because you are calling wait_for_playback in an infinite loop. That is, your player core will quit (which stops playback), but you will continue waiting for playback to finish (which will never happen). Meanwhile, the player window is still open since that one is kept open due to the libmpv config we're using here and will only close after you call player.terminate().

Here's some code that seems to work for me:

#!/usr/bin/env python3
import mpv
import time

player = mpv.MPV(config='yes', input_default_bindings=True)

@player.on_key_press('CLOSE_WIN')
def quit():
    player.terminate()

player.play('LGR Plays - Goat Simulator-j4HY_fxwiZo.mp4')
player.wait_for_playback()
while True:
    # For demonstration purposes, do something else instead of terminating the python process.
    time.sleep(1)

Another variant would be the following. Note the place where player.terminate() is called.

#!/usr/bin/env python3
import mpv
import time

player = mpv.MPV(config='yes', input_default_bindings=True)

player.register_key_binding('CLOSE_WIN', 'quit')

player.play('LGR Plays - Goat Simulator-j4HY_fxwiZo.mp4')
player.wait_for_playback()
player.terminate()
while True:
    # For demonstration purposes, do something else instead of terminating the python process.
    time.sleep(1)

from python-mpv.

stax76 avatar stax76 commented on August 27, 2024

I was evaluating all options and will much likely settle for C# because I have 15 years VB.NET experience and made a lot progress in my prototype. For every project I do I try to use a different language, with Python I'm a total n00b but I like the syntax a lot so I'll definitively look forward to learn and use it in the future.

Danke fΓΌr die Hilfe

from python-mpv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.