Add delete flag to stop_audio, clean duplicate code.

This commit is contained in:
Bill Dengler 2015-05-13 21:34:26 -04:00
parent 5f8760a0a9
commit 1d1c07caca

View File

@ -115,11 +115,8 @@ class URLStream(object):
self.prepared = True self.prepared = True
def play(self, url=None, volume=1.0, stream=None,announce=True): def play(self, url=None, volume=1.0, stream=None,announce=True):
if hasattr(self, "stream") and self.stream.is_playing: if self.stop_audio(delete=True):
output.speak(_(u"Stopped")) return
self.stream.stop()
del self.stream
log.debug("Stream stopped")
else: else:
if announce: if announce:
output.speak(_(u"Playing...")) output.speak(_(u"Playing..."))
@ -147,11 +144,17 @@ class URLStream(object):
except: except:
print "Exception." print "Exception."
return False return False
def stop_audio(self): def stop_audio(self,delete=False):
if hasattr(self, "stream") and self.stream.is_playing == True: if hasattr(self, "stream") and self.stream.is_playing:
output.speak("Stopped.",True) output.speak("Stopped.",True)
self.stream.stop() self.stream.stop()
log.debug("Stopped audio stream.")
if delete:
del self.stream
log.debug("Deleted audio stream.")
return True
else:
return False
@staticmethod @staticmethod
def delete_old_tempfiles(): def delete_old_tempfiles():
for f in glob(os.path.join(tempfile.gettempdir(), 'tmp*.wav')): for f in glob(os.path.join(tempfile.gettempdir(), 'tmp*.wav')):