vlc-python, Ubuntu 18.04: Detect if the video window was closed
Posted: 16 Jan 2020 18:11
I have a Python app that plays parts of a large media file, and monitors the current player position to jump automatically to another location, where appropriate.
I'd like to exit from the app automatically, when user closes the video window. But I don't know how to detect it. Here's my test code, as I execute it in Python interactive console:
If I then close the video window, I see the following text outputed in console:
However, I can still access the player object properties, and even unpause it, pause it after short time and see that it's `get_time()` method returns new value:
I hoped that the `player.get_xwindow()` could be a way to detect if the window was closed, but it returns `0` both before and after closing the video window.
So, what would be a reliable way to do it?
I'd like to exit from the app automatically, when user closes the video window. But I don't know how to detect it. Here's my test code, as I execute it in Python interactive console:
Code: Select all
import vlc
player = vlc.MediaPlayer("Test.mp4")
player.play()
# After some time
player.pause()
Code: Select all
>>> [00007f95e80c75f0] xcb_window window error: X server failure
Code: Select all
>>> player.get_state()
vlc.State.Paused
>>> player.get_time()
3395
>>> player.pause()
...
>>> player.pause()
>>> player.get_time()
4394
So, what would be a reliable way to do it?