File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
adafruit_circuitplayground Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -672,22 +672,19 @@ def play_file(self, file_name):
672
672
cpx.play_file("rimshot.wav")
673
673
"""
674
674
# Play a specified file.
675
+ self .stop_tone ()
675
676
self ._speaker_enable .value = True
676
- try :
677
- if sys .implementation .version [0 ] >= 3 :
678
- audio = audioio .AudioOut (board .SPEAKER )
679
- file = audioio .WaveFile (open (file_name , "rb" ))
680
- audio .play (file )
677
+ if sys .implementation .version [0 ] >= 3 :
678
+ with audioio .AudioOut (board .SPEAKER ) as audio :
679
+ wavefile = audioio .WaveFile (open (file_name , "rb" ))
680
+ audio .play (wavefile )
681
681
while audio .playing :
682
682
pass
683
- audio .deinit ()
684
- else :
685
- audio = audioio .AudioOut (board .SPEAKER , open (file_name , "rb" ))
683
+ else :
684
+ with audioio .AudioOut (board .SPEAKER , open (file_name , "rb" )) as audio :
686
685
audio .play ()
687
686
while audio .playing :
688
687
pass
689
- except RuntimeError :
690
- pass
691
688
self ._speaker_enable .value = False
692
689
693
690
You can’t perform that action at this time.
0 commit comments