Soft 404
Hey I'm new to this and can follow the wiring diagrams just fine, copy and paste just fine.
I have tried a couple of the code examples for mp3 playback that seem to work good, with the intent to make a noise or rain machine, but cant get the files to play in a loop.
------- original example -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
"""
CircuitPython multiple MP3 playback example for Raspberry Pi Pico.
Plays two MP3 files consecutively, once time each.
"""
import board
import audiomp3
import audiopwmio
audio = audiopwmio.PWMAudioOut(board.GP0)
mp3files = ["rain1.mp3", "rain2.mp3"]
mp3 = open(mp3files[0], "rb")
decoder = audiomp3.MP3Decoder(mp3)
for filename in mp3files:
decoder.file = open(filename, "rb")
audio.play(decoder)
print("Playing:", filename)
while audio.playing:
pass
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks if you have a working idea.
Thanks that worked after about half hour, when I realized the T in true needed to be True, per your example.
Thanks again.
Won't you need to close the files when they're no longer being used, or does Python handle that kind of thing for you?
I should have done a quick search first. This page
says
Python automatically closes a file when the reference object of a file is reassigned to another file.
so it looks like you're fairly safe in what you're doing.
I should have done a quick search first. This page
says
Python automatically closes a file when the reference object of a file is reassigned to another file.
so it looks like you're fairly safe in what you're doing.