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

This forum is about all development around libVLC.
Passiday
New Cone
New Cone
Posts: 5
Joined: 28 Jan 2019 20:31

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

Postby Passiday » 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:

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?

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

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

Postby Rémi Denis-Courmont » 16 Jan 2020 18:50

Create your own window and manage it however you see fit.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Passiday
New Cone
New Cone
Posts: 5
Joined: 28 Jan 2019 20:31

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

Postby Passiday » 16 Jan 2020 22:56

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.

mediajoy
New Cone
New Cone
Posts: 4
Joined: 21 Jul 2021 11:49

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

Postby mediajoy » 08 Oct 2021 00:29

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. :)

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

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

Postby Rémi Denis-Courmont » 09 Oct 2021 20:49

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.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

mediajoy
New Cone
New Cone
Posts: 4
Joined: 21 Jul 2021 11:49

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

Postby mediajoy » 10 Oct 2021 00:21

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.

Krilya
New Cone
New Cone
Posts: 6
Joined: 02 Aug 2022 10:30

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

Postby Krilya » 02 Aug 2022 11:04

You need to set the delete window protocol to a function that includes player.stop()


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 18 guests