From dfdbe3c5f422299dbdc0f3393962a71a25e96daf Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 10 Sep 2021 15:05:05 -0500 Subject: [PATCH] Close VLC window after video playback ends. Close #399 --- doc/changelog.md | 1 + src/sound.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/doc/changelog.md b/doc/changelog.md index 428a2174..3b8931e7 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,7 @@ ## changes in this version +* TWBlue now closes the VLC player window automatically when a video reaches its end. ([#399](https://github.com/manuelcortez/TWBlue/issues/399)) * After a lot of time, TWBlue now uses a new default Soundpack, called FreakyBlue. This soundpack will be set by default in all new sessions created in the application. Thanks to [Andre Louis](https://twitter.com/FreakyFwoof) for the pack. ([#247](https://github.com/manuelcortez/TWBlue/issues/247)) * When reading a tweet, if the tweet contains more than 2 consecutive mentions, TWBlue will announce how many more users the tweet includes, as opposed to read every user in the conversation. You still can display the tweet to read all users. * In the tweet displayer, It is possible to copy a link to the current tweet or person by pressing a button called "copy link to clipboard". diff --git a/src/sound.py b/src/sound.py index 1cd8ad78..df47f221 100644 --- a/src/sound.py +++ b/src/sound.py @@ -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) \ No newline at end of file