From 432e40bdfae9ab64844745ed567c613af0128642 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Thu, 14 May 2015 10:01:37 -0400 Subject: [PATCH] Fix audio playback. --- src/controller/buffersController.py | 4 ++-- src/sound.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index a1e0cc60..d08854ad 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -437,6 +437,8 @@ class baseBufferController(bufferController): @_tweets_exist def interact(self): "Select the best action for the currently focused tweet (audio, geocode, URL, etc)." + if hasattr(sound.URLPlayer,'stream'): + return sound.URLPlayer.stop_audio(delete=True) tweet = self.get_tweet() url=None urls = utils.find_urls(tweet) @@ -449,8 +451,6 @@ class baseBufferController(bufferController): url=urls_list.get_string() if hasattr(urls_list, "destroy"): urls_list.destroy() if url != None: - if hasattr(sound.URLPlayer,'stream'): - return sound.URLPlayer.stop_audio(delete=True) output.speak("Opening media...",True) if sound.URLPlayer.is_playable(url=url,play=True,volume=self.session.settings["sound"]["volume"]) == False: return webbrowser.open_new_tab(url) diff --git a/src/sound.py b/src/sound.py index 5e8948ee..6ffaca52 100644 --- a/src/sound.py +++ b/src/sound.py @@ -12,6 +12,7 @@ import platform import output system = platform.system() from mysc.repeating_timer import RepeatingTimer +from mysc.thread_utils import call_threaded import application URLPlayer = None @@ -131,7 +132,7 @@ class URLStream(object): self.stream.volume = float(volume) self.stream.play() log.debug("played") - del self.stream + call_threaded(self.delete_when_done) def is_playable(self, url,play=False,volume=1.0): try: log.debug("Checking URL playability...") @@ -143,11 +144,19 @@ class URLStream(object): return True except: return False + def delete_when_done(self): + while hasattr(self,'stream') and self.stream.is_playing: + pass + del self.stream + def stop_audio(self,delete=False): - if hasattr(self, "stream") and self.stream.is_playing: + if hasattr(self, "stream"): output.speak("Stopped.",True) - self.stream.stop() - log.debug("Stopped audio stream.") + try: + self.stream.stop() + log.debug("Stopped audio stream.") + except: + log.exception("Exception while stopping stream.") if delete: del self.stream log.debug("Deleted audio stream.")