You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# https://github.com/gallaugher/disco-button/blob/main/demo_of_sd_mp3_play_break_with_sd.py# note repo above also has mount_sd.py, but it's the standard one that's from Adafruit's learn guide# Just a test of playing MP3 files when pushing a buttonimportboard, time, microcontroller, mount_sd, digitalio, randomfromaudiopwmioimportPWMAudioOutasAudioOutfromaudiomp3importMP3Decoderfromadafruit_debouncerimportButton# create a debounced Buttonbutton_input=digitalio.DigitalInOut(board.GP21)
button_input.switch_to_input(pull=digitalio.Pull.UP) # False when pressed, True when not pressedbutton=Button(button_input)
# setup the speakeraudio=AudioOut(board.GP15) # assuming speaker plug tip to GP16# set path where audio files can be found on devicepath="/sd/disco_songs/"# set up the mp3 decoderfilename="Boogie Wonderland.mp3"mp3_file=open(path+filename, "rb")
decoder=MP3Decoder(mp3_file)
# song is normally sent over MQTTsongs= ["Disco Inferno",
"Boogie Wonderland",
"Play That Funky Music",
"Stayin' Alive"]
# play an mp3 file - pass in string that includes filename extensiondefplay_mp3(filename):
# if audio.playing:# audio.stop()print(f"About to play {path+filename}")
try:
decoder.file=open(path+filename, "rb")
audio.play(decoder)
exceptOSErrorase:
print(f"No such file/directory: {path+filename}\nERROR: {e}\nRESTARTING")
time.sleep(5.0)
audio.stop()
except:
print("UNKNOWN ERROR - RESTARTING - error while playing sound")
time.sleep(5.0)
microcontroller.reset()
whileTrue:
button.update()
ifbutton.pressed:
print("BUTTON PRESSED")
song=random.choice(songs)+".mp3"play_mp3(song)
ifbutton.released:
print("button released")
Behavior
Big squelchy crash that freezes the board. No exception thrown to the serial console.
Description
DanH suggested I post this issue after a conversation on Discord. I noticed when using a Raspberry Pi Pico W & Adafruit SD/SDIO card breakout that randomly (but often) mp3 playback will crash & freeze completely without throwing an error if an mp3 file is played over an existing mp3 file.
Here's a URL showing code that you can use to replicate the crash. Pressing buttons will randomly play an mp3 file (these are four full-length popular disco songs - can't share here due to copyright, but you should be able to get these, or DM me for private send for educational purposes). If you press the button every few seconds you'll eventually crash, often with a squelching loud sound, but no exception thrown.
I was able to work around this by using the commented out code that checks to see if am mp3 file is playing & if so, issues a .stop()
As always - thanks for your work, team. You are all truly wonderful humans! https://github.com/gallaugher/disco-button/blob/main/demo_of_sd_mp3_play_break_with_sd.py
Additional information
No response
The text was updated successfully, but these errors were encountered:
CircuitPython version
Code/REPL
Behavior
Big squelchy crash that freezes the board. No exception thrown to the serial console.
Description
DanH suggested I post this issue after a conversation on Discord. I noticed when using a Raspberry Pi Pico W & Adafruit SD/SDIO card breakout that randomly (but often) mp3 playback will crash & freeze completely without throwing an error if an mp3 file is played over an existing mp3 file.
Here's a URL showing code that you can use to replicate the crash. Pressing buttons will randomly play an mp3 file (these are four full-length popular disco songs - can't share here due to copyright, but you should be able to get these, or DM me for private send for educational purposes). If you press the button every few seconds you'll eventually crash, often with a squelching loud sound, but no exception thrown.
I was able to work around this by using the commented out code that checks to see if am mp3 file is playing & if so, issues a .stop()
As always - thanks for your work, team. You are all truly wonderful humans!
https://github.com/gallaugher/disco-button/blob/main/demo_of_sd_mp3_play_break_with_sd.py
Additional information
No response
The text was updated successfully, but these errors were encountered: