File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
adafruit_circuitplayground Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -649,6 +649,8 @@ def stop_tone(self):
649649 # Stop playing any tones.
650650 if self ._sample is not None and self ._sample .playing :
651651 self ._sample .stop ()
652+ self ._sample .deinit ()
653+ self ._sample = None
652654 self ._speaker_enable .value = False
653655
654656 def play_file (self , file_name ):
@@ -670,18 +672,19 @@ def play_file(self, file_name):
670672 cpx.play_file("rimshot.wav")
671673 """
672674 # Play a specified file.
675+ self .stop_tone ()
673676 self ._speaker_enable .value = True
674677 if sys .implementation .version [0 ] >= 3 :
675- audio = audioio .AudioOut (board .SPEAKER )
676- file = audioio .WaveFile (open (file_name , "rb" ))
677- audio .play (file )
678- while audio .playing :
679- pass
678+ with audioio .AudioOut (board .SPEAKER ) as audio :
679+ wavefile = audioio .WaveFile (open (file_name , "rb" ))
680+ audio .play (wavefile )
681+ while audio .playing :
682+ pass
680683 else :
681- audio = audioio .AudioOut (board .SPEAKER , open (file_name , "rb" ))
682- audio .play ()
683- while audio .playing :
684- pass
684+ with audioio .AudioOut (board .SPEAKER , open (file_name , "rb" )) as audio :
685+ audio .play ()
686+ while audio .playing :
687+ pass
685688 self ._speaker_enable .value = False
686689
687690
You can’t perform that action at this time.
0 commit comments