mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Fix audio playback.
This commit is contained in:
parent
f0e1f74d03
commit
432e40bdfa
@ -437,6 +437,8 @@ class baseBufferController(bufferController):
|
|||||||
@_tweets_exist
|
@_tweets_exist
|
||||||
def interact(self):
|
def interact(self):
|
||||||
"Select the best action for the currently focused tweet (audio, geocode, URL, etc)."
|
"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()
|
tweet = self.get_tweet()
|
||||||
url=None
|
url=None
|
||||||
urls = utils.find_urls(tweet)
|
urls = utils.find_urls(tweet)
|
||||||
@ -449,8 +451,6 @@ class baseBufferController(bufferController):
|
|||||||
url=urls_list.get_string()
|
url=urls_list.get_string()
|
||||||
if hasattr(urls_list, "destroy"): urls_list.destroy()
|
if hasattr(urls_list, "destroy"): urls_list.destroy()
|
||||||
if url != None:
|
if url != None:
|
||||||
if hasattr(sound.URLPlayer,'stream'):
|
|
||||||
return sound.URLPlayer.stop_audio(delete=True)
|
|
||||||
output.speak("Opening media...",True)
|
output.speak("Opening media...",True)
|
||||||
if sound.URLPlayer.is_playable(url=url,play=True,volume=self.session.settings["sound"]["volume"]) == False:
|
if sound.URLPlayer.is_playable(url=url,play=True,volume=self.session.settings["sound"]["volume"]) == False:
|
||||||
return webbrowser.open_new_tab(url)
|
return webbrowser.open_new_tab(url)
|
||||||
|
17
src/sound.py
17
src/sound.py
@ -12,6 +12,7 @@ import platform
|
|||||||
import output
|
import output
|
||||||
system = platform.system()
|
system = platform.system()
|
||||||
from mysc.repeating_timer import RepeatingTimer
|
from mysc.repeating_timer import RepeatingTimer
|
||||||
|
from mysc.thread_utils import call_threaded
|
||||||
import application
|
import application
|
||||||
URLPlayer = None
|
URLPlayer = None
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ class URLStream(object):
|
|||||||
self.stream.volume = float(volume)
|
self.stream.volume = float(volume)
|
||||||
self.stream.play()
|
self.stream.play()
|
||||||
log.debug("played")
|
log.debug("played")
|
||||||
del self.stream
|
call_threaded(self.delete_when_done)
|
||||||
def is_playable(self, url,play=False,volume=1.0):
|
def is_playable(self, url,play=False,volume=1.0):
|
||||||
try:
|
try:
|
||||||
log.debug("Checking URL playability...")
|
log.debug("Checking URL playability...")
|
||||||
@ -143,11 +144,19 @@ class URLStream(object):
|
|||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
return False
|
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):
|
def stop_audio(self,delete=False):
|
||||||
if hasattr(self, "stream") and self.stream.is_playing:
|
if hasattr(self, "stream"):
|
||||||
output.speak("Stopped.",True)
|
output.speak("Stopped.",True)
|
||||||
self.stream.stop()
|
try:
|
||||||
log.debug("Stopped audio stream.")
|
self.stream.stop()
|
||||||
|
log.debug("Stopped audio stream.")
|
||||||
|
except:
|
||||||
|
log.exception("Exception while stopping stream.")
|
||||||
if delete:
|
if delete:
|
||||||
del self.stream
|
del self.stream
|
||||||
log.debug("Deleted audio stream.")
|
log.debug("Deleted audio stream.")
|
||||||
|
Loading…
Reference in New Issue
Block a user