mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Add delete flag to stop_audio, clean duplicate code.
This commit is contained in:
parent
5f8760a0a9
commit
1d1c07caca
19
src/sound.py
19
src/sound.py
@ -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')):
|
||||||
|
Loading…
Reference in New Issue
Block a user