adafruit / Adafruit_CircuitPython_CircuitPlayground

CircuitPython library for Circuit Playground Express
MIT License
91 stars 71 forks source link

add play_mp3 function to bluefruit module #95

Closed FoamyGuy closed 4 years ago

FoamyGuy commented 4 years ago

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 commented 4 years ago

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:

kattni commented 4 years ago

@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 commented 4 years ago

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 :smile:

kattni commented 4 years ago

@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!