Close VLC window after video playback ends. Close #399

This commit is contained in:
2021-09-10 15:05:05 -05:00
parent fbe93ea4be
commit dfdbe3c5f4
2 changed files with 9 additions and 0 deletions

View File

@@ -114,6 +114,8 @@ class URLStream(object):
# LibVLC controls.
self.instance = vlc.Instance()
self.player = self.instance.media_player_new()
self.event_manager = self.player.event_manager()
self.event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.end_callback)
def prepare(self, url):
""" Takes an URL and prepares it to be streamed. This function will try to unshorten the passed URL and, if needed, to transform it into a valid URL."""
@@ -158,3 +160,9 @@ class URLStream(object):
def stop_audio(self):
output.speak(_(u"Stopped."), True)
self.player.stop()
def end_callback(self, event, *args, **kwargs):
call_threaded(self.player.stop)
def __del__(self):
self.event_manager.event_detach(vlc.EventType.MediaPlayerEndReached)