code.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  CircuitPython multiple MP3 playback example for Raspberry Pi Pico.
 7  Plays two MP3 files consecutively, once time each.
 8  """
 9  import board
10  import audiomp3
11  import audiopwmio
12  
13  audio = audiopwmio.PWMAudioOut(board.GP0)
14  
15  mp3files = ["slow.mp3", "happy.mp3"]
16  
17  mp3 = open(mp3files[0], "rb")
18  decoder = audiomp3.MP3Decoder(mp3)
19  
20  for filename in mp3files:
21      decoder.file = open(filename, "rb")
22      audio.play(decoder)
23      print("Playing:", filename)
24      while audio.playing:
25          pass
26  
27  print("Done playing!")