Open r41d opened 5 years ago
Do you really need to create another MPV instance every call? If that is really needed, try video_player.quit()
at the end of the function.
I tried out a bit and for me this works best:
def play_demo_video(self, video_file_name):
video_player = mpv.MPV(input_default_bindings=True, input_vo_keyboard=True)
# When the video plays we want to disable gamepad input for the game
self._disable_input_for_video = True
# In order to quit the mpv on any button press, we use "antimicro" to map controller input to the q button
# on demand and exit mpv that way. Don't know if there's a better option or not
antimicro = subprocess.Popen(["antimicro", "-d", "--hidden", "--profile", "controller_q_map.gamecontroller.amgp"])
def cleanup_mpv():
# Clean up the helpers
self._disable_input_for_video = False
self.get_screen()._last_action_timestamp = datetime.now()
# make pygame grab the focus again
subprocess.call(["wmctrl", "-a", PROGRAM_NAME])
@video_player.on_key_press('q')
def my_q_binding():
video_player.quit()
cleanup_mpv()
@video_player.event_callback('END_FILE')
def video_finished_handler(event):
video_player.terminate()
cleanup_mpv()
...
With the quit for when we press q and the terminate for when the file ended. Most other combinations lead to Core Dump crashes...
If you use mpv to play videos (since I assume normal human cannot watch more than one video at the same time), why don't you keep an MPV instance as a variable in the scope of the game that call it, or a attribute of the class if you're doing OO?
I want to go back to the game when no video is playing. For this I would need the MPV window to go away without shutting down the mpv instance. How would I achieve that?
You can try to cycle
the video
property either through the API or by the binding _
.
What might work is providing mpv with a window to draw into using the --wid
option. As far as I know that "window" can be a GUI component such as a panel that is part of another window on most platforms and GUI frameworks. Perhaps it is then possible to hide/show that GUI component, thereby hiding/showing the mpv window. The PyQt embedding example might be a good starting point for experiments here.
I have a program where mpv is called multiple times, like, every minute, but the previous playback is always done before a new one is started. After about 16 times I get the following crash:
Unfortunately I have no idea how to deal with this crash :/
The code that invokes mpv looks like this (part of a game made with pygame):
Any advice would be appreciated.