Page 1 of 1

vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 16 Jan 2020 18:11
by Passiday
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:

Code: Select all

import vlc player = vlc.MediaPlayer("Test.mp4") player.play() # After some time player.pause()
If I then close the video window, I see the following text outputed in console:

Code: Select all

>>> [00007f95e80c75f0] xcb_window window error: X server failure
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:

Code: Select all

>>> player.get_state() vlc.State.Paused >>> player.get_time() 3395 >>> player.pause() ... >>> player.pause() >>> player.get_time() 4394
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?

Re: vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 16 Jan 2020 18:50
by Rémi Denis-Courmont
Create your own window and manage it however you see fit.

Re: vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 16 Jan 2020 22:56
by Passiday
Sure, I was just hoping I can avoid all the hassle of setting up my own window etc. I am totally happy with the default window that pops up when I load andplay the MediaPlayer instance with a video file.

Re: vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 08 Oct 2021 00:29
by mediajoy
Hello everyone, :)
I know this thread is more than a year old but I have the same problem. I use the C++ libvlcpp bindings and also can not find any option to check if the window was closed. Maybe there is a method I am missing out?

When I close the window, the vlc library outputs:

Code: Select all

xcb_window window error: X server failure
But the program continues working in the background without any window. To restart the program, I have to kill it manually. This is not the expected behaviour for the user!

I have tried to create my own X window with XCB, but this is quite complicated, and seems overkill only for an additional check if a window was closed. :( Also, libvlc already manages a window pretty well and even handles X events such as double-click to toggle fullscreen and it hides the cursor if it enters the window. (libvlc even handles handles the double-click event if I create my own X window, which is odd.)

Finally, if there would be just another function, which returns the state of the window (open, closed or killed), that would be all I need. If it returns a value which indicates window destruction I would exit my program.

I would appreciate a lot, if you would add such a function. :)

Re: vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 09 Oct 2021 20:49
by Rémi Denis-Courmont
Closing the window ends the video rendering - in theory. In practice, most GL drivers will either crash or abort the process.

Either way, this is probably not what you want, so then you have to provide your own window.

Re: vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 10 Oct 2021 00:21
by mediajoy
I actually want my program to be aborted, when the window is closed, but this is not what happens. Instead it continues running in the background.

Re: vlc-python, Ubuntu 18.04: Detect if the video window was closed

Posted: 02 Aug 2022 11:04
by Krilya
You need to set the delete window protocol to a function that includes player.stop()