Skip to content

add play_mp3 function to bluefruit module #95

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 4 commits into from
Jun 17, 2020

Conversation

FoamyGuy
Copy link
Contributor

This adds a play_mp3 function that is analogous to play_file but supports mp3 files instead of wav.

The module required for mp3 playback audiomp3 isn't available on the CPX, so this function is available only to CPB devices.

Example usage:

from adafruit_circuitplayground import cp
while True:
    if cp.button_a:
        cp.play_mp3("laugh.mp3")
    elif cp.button_b:
        cp.play_mp3("rimshot.mp3")

@FoamyGuy
Copy link
Contributor Author

This is working and passing the CI now. I think there are a few open questions related to it that come to mind for me:

  • Does the express module need to raise unsupported error for play_mp3
  • Should play_file ultimately get renamed to play_wav

@FoamyGuy FoamyGuy requested a review from a team June 15, 2020 13:04
@ladyada ladyada requested a review from kattni June 15, 2020 15:13
@kattni
Copy link
Contributor

kattni commented Jun 15, 2020

@FoamyGuy Yes to the unsupported - you can add it to the current list the same way the other two are already there. No to the rename, unless you can think of a seamless to make it so both names work - we don't want to break all the current code.

@FoamyGuy
Copy link
Contributor Author

Thank you @kattni the latest commit makes play_mp3 use _unsupported in the express module.
Here's how it works on the cpx now:

>>> from adafruit_circuitplayground import cp
>>> cp.play_mp3("test.mp3")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_circuitplayground/express.py", line 82, in _unsupported
NotImplementedError: This feature is not supported on Circuit Playground Express.

I have learned a ton recent about structuring modules by working on this and the pybadger library. Thanks for making these so easy to extend with new functionalities 😄

@kattni
Copy link
Contributor

kattni commented Jun 16, 2020

@FoamyGuy This is great! I'd like you to add one more thing - an example in the examples folder. Please name it circuitplayground_bluefruit_play_mp3.py and include a doc string similar to the one found in this file: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/blob/master/examples/circuitplayground_bluefruit_loud_sound.py
Thanks!

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this!

@kattni kattni merged commit 3c54032 into adafruit:master Jun 17, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants