Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adafruit_fruitjam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def __init__( # noqa: PLR0912,PLR0913,Too many branches,Too many arguments in f

self.sd_check = self.peripherals.sd_check
self.play_file = self.peripherals.play_file
self.play_mp3_file = self.peripherals.play_mp3_file
self.stop_play = self.peripherals.stop_play

self.image_converter_url = self.network.image_converter_url
Expand Down
14 changes: 14 additions & 0 deletions adafruit_fruitjam/peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def __init__(self):
except OSError:
# sdcard init or mounting failed
self._sd_mounted = False
self._mp3_decoder = None

@property
def button1(self) -> bool:
Expand Down Expand Up @@ -247,6 +248,19 @@ def play_file(self, file_name, wait_to_finish=True):
pass
self.wavfile.close()

def play_mp3_file(self, filename):
with open(filename, "rb") as f:
if self._mp3_decoder is None:
from audiomp3 import MP3Decoder # noqa: PLC0415, import outside top-level

self._mp3_decoder = MP3Decoder(f)
else:
self._mp3_decoder.file = f

self.audio.play(self._mp3_decoder)
while self.audio.playing:
pass

def stop_play(self):
"""Stops playing a wav file."""
self.audio.stop()
Expand Down