Comments (4)
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.
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.
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.
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)
- macOS: libmpv cannot get a VO. HOT 11
- Gapless playback not always working HOT 2
- python-mpv not finding libmpv DLL on MSYS2 HOT 7
- no-border not working as intended HOT 1
- tests/test_mpv.py::TestLifecycle::test_wait_for_event_shutdown hangs HOT 1
- Audio controls
- I do not literally know which DLLs does it need to consume HOT 2
- How to directly play audio bytes? HOT 2
- "Cannot find libmpv in the usual places" on Arch Linux, Hypnotix HOT 2
- How to replace mpv.MpvEventID.METADATA_UPDATE ? HOT 2
- Loadfile command broken by API change in mpv v0.38.0 HOT 5
- The PyPI package is not up to date HOT 3
- playlist_next() and playlist_prev() beyond end of playlist causes SystemError HOT 1
- [QUESTION] How do I add custom scripts? HOT 2
- QOpenGLWidget is displayed in its own window since ibmpv.so.2.3.0 HOT 3
- SyntaxError on Mac os with python3 on v1.0.6 HOT 2
- Unable to set Gapless Playback option HOT 3
- Is it possible to read music files from an USB key or HD ? HOT 1
- trying to capture mouse clicks when running mpv HOT 2
- wait_until_playing and wait_for_property throws exception HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-mpv.