Skip to content

Updates play_file to work with 3.0 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The MIT License (MIT)
#
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
# Copyright (c) 2017 Kattni Rembor for Adafruit Industries
# Copyright (c) 2017-2018 Kattni Rembor for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

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

"""
Expand Down Expand Up @@ -689,11 +689,17 @@ def play_file(self, file_name):
"""
# Play a specified file.
self._speaker_enable.value = True
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))

audio.play()
while audio.playing:
pass
if sys.implementation.version[0] >= 3:
audio = audioio.AudioOut(board.SPEAKER)
file = audioio.WaveFile(open(file_name, "rb"))
audio.play(file)
while audio.playing:
pass
else:
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))
audio.play()
while audio.playing:
pass
self._speaker_enable.value = False


Expand Down