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):
649
649
# Stop playing any tones.
650
650
if self ._sample is not None and self ._sample .playing :
651
651
self ._sample .stop ()
652
+ self ._sample .deinit ()
653
+ self ._sample = None
652
654
self ._speaker_enable .value = False
653
655
654
656
def play_file (self , file_name ):
@@ -670,18 +672,19 @@ def play_file(self, file_name):
670
672
cpx.play_file("rimshot.wav")
671
673
"""
672
674
# Play a specified file.
675
+ self .stop_tone ()
673
676
self ._speaker_enable .value = True
674
677
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
680
683
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
685
688
self ._speaker_enable .value = False
686
689
687
690
You can’t perform that action at this time.
0 commit comments