Skip to content

Commit f66b129

Browse files
committed
Linted
1 parent 13ac90b commit f66b129

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

adafruit_pyportal/peripherals.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,14 @@ def play_file(self, file_name, wait_to_finish=True):
146146
:param str file_name: The name of the wav file to play on the speaker.
147147
148148
"""
149-
wavfile = open(file_name, "rb")
150-
wavedata = audiocore.WaveFile(wavfile)
151-
self._speaker_enable.value = True
152-
self.audio.play(wavedata)
153-
if not wait_to_finish:
154-
return
155-
while self.audio.playing:
156-
pass
157-
wavfile.close()
149+
with open(file_name, "rb") as wavfile:
150+
wavedata = audiocore.WaveFile(wavfile)
151+
self._speaker_enable.value = True
152+
self.audio.play(wavedata)
153+
if not wait_to_finish:
154+
return
155+
while self.audio.playing:
156+
pass
158157
self._speaker_enable.value = False
159158

160159
def sd_check(self):

0 commit comments

Comments
 (0)