mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Fix audio playback.
This commit is contained in:
parent
f0e1f74d03
commit
432e40bdfa
@ -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)
|
||||
|
13
src/sound.py
13
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)
|
||||
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.")
|
||||
|
Loading…
Reference in New Issue
Block a user