Skip to content

Commit d82fb23

Browse files
authored
Merge pull request #32 from kattni/cp-3-update
Updates play_file to work with 3.0
2 parents a669915 + c198e84 commit d82fb23

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

adafruit_circuitplayground/express.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The MIT License (MIT)
22
#
33
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
4-
# Copyright (c) 2017 Kattni Rembor for Adafruit Industries
4+
# Copyright (c) 2017-2018 Kattni Rembor for Adafruit Industries
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
@@ -21,7 +21,7 @@
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
# THE SOFTWARE.
2323

24-
# We have a lot of attributes for this complex sensor.
24+
# We have a lot of attributes for this complex library.
2525
# pylint: disable=too-many-instance-attributes
2626

2727
"""
@@ -689,11 +689,17 @@ def play_file(self, file_name):
689689
"""
690690
# Play a specified file.
691691
self._speaker_enable.value = True
692-
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))
693-
694-
audio.play()
695-
while audio.playing:
696-
pass
692+
if sys.implementation.version[0] >= 3:
693+
audio = audioio.AudioOut(board.SPEAKER)
694+
file = audioio.WaveFile(open(file_name, "rb"))
695+
audio.play(file)
696+
while audio.playing:
697+
pass
698+
else:
699+
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))
700+
audio.play()
701+
while audio.playing:
702+
pass
697703
self._speaker_enable.value = False
698704

699705

0 commit comments

Comments
 (0)