mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-21 07:16:07 -04:00
#34: just playing around a bit. Really broken right now.
This commit is contained in:
22
src/sound.py
22
src/sound.py
@@ -13,6 +13,7 @@ import output
|
||||
system = platform.system()
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
import application
|
||||
import time
|
||||
URLPlayer = None
|
||||
|
||||
def setup():
|
||||
@@ -114,7 +115,7 @@ class URLStream(object):
|
||||
log.debug("Transformed URL: %s. Prepared" % (self.url,))
|
||||
self.prepared = True
|
||||
|
||||
def play(self, url, volume=1.0):
|
||||
def play(self, url=None, volume=1.0, stream=None):
|
||||
if hasattr(self, "stream") and self.stream.is_playing:
|
||||
output.speak(_(u"Stopped"))
|
||||
self.stream.stop()
|
||||
@@ -123,21 +124,34 @@ class URLStream(object):
|
||||
else:
|
||||
output.speak(_(u"Playing..."))
|
||||
log.debug("Attempting to play an URL...")
|
||||
self.prepare(url)
|
||||
if url != None:
|
||||
self.prepare(url)
|
||||
elif stream != None:
|
||||
self.stream=stream
|
||||
if self.prepared == True:
|
||||
self.stream = sound_lib.stream.URLStream(url=self.url)
|
||||
if hasattr(self,'stream'):
|
||||
self.stream.volume = float(volume)
|
||||
self.stream.play()
|
||||
log.debug("played")
|
||||
|
||||
def is_playable(self, url):
|
||||
def is_playable(self, url,play=False,volume=1.0):
|
||||
print "Playability test invoked."
|
||||
start=time.time()
|
||||
try:
|
||||
log.debug("Checking URL playability...")
|
||||
self.prepare(url)
|
||||
if self.prepared == True:
|
||||
self.stream = sound_lib.stream.URLStream(url=self.url)
|
||||
stream=sound_lib.stream.URLStream(url=self.url)
|
||||
end=time.time()
|
||||
print "is_playable algo took",end-start,"seconds."
|
||||
if play:
|
||||
return self.play(stream=stream,volume=volume)
|
||||
return True
|
||||
except:
|
||||
log.exception("Exception.")
|
||||
end=time.time()
|
||||
print "is_playable algo took",end-start,"seconds."
|
||||
return False
|
||||
def stop_audio(self):
|
||||
if hasattr(self, "stream") and self.stream.is_playing == True:
|
||||
|
Reference in New Issue
Block a user