Skip to content

Commit 4a4555b

Browse files
committed
Added try/except to play_file
1 parent 13c4623 commit 4a4555b

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

adafruit_circuitplayground/express.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,21 @@ def play_file(self, file_name):
673673
"""
674674
# Play a specified file.
675675
self._speaker_enable.value = True
676-
if sys.implementation.version[0] >= 3:
677-
audio = audioio.AudioOut(board.SPEAKER)
678-
file = audioio.WaveFile(open(file_name, "rb"))
679-
audio.play(file)
680-
while audio.playing:
681-
pass
682-
audio.deinit()
683-
else:
684-
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))
685-
audio.play()
686-
while audio.playing:
687-
pass
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)
681+
while audio.playing:
682+
pass
683+
audio.deinit()
684+
else:
685+
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))
686+
audio.play()
687+
while audio.playing:
688+
pass
689+
except RuntimeError:
690+
pass
688691
self._speaker_enable.value = False
689692

690693

0 commit comments

Comments
 (0)