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):
672672 cpx.play_file("rimshot.wav")
673673 """
674674 # Play a specified file.
675+ self .stop_tone ()
675676 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 )
681681 while audio .playing :
682682 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 :
686685 audio .play ()
687686 while audio .playing :
688687 pass
689- except RuntimeError :
690- pass
691688 self ._speaker_enable .value = False
692689
693690
You can’t perform that action at this time.
0 commit comments