Merge pull request #15 from FoamyGuy/play_mp3_file
Some checks failed
Build CI / test (push) Has been cancelled
Some checks failed
Build CI / test (push) Has been cancelled
play_mp3_file() function
This commit is contained in:
commit
e67239b37b
2 changed files with 14 additions and 0 deletions
|
|
@ -193,6 +193,7 @@ class FruitJam(PortalBase):
|
||||||
|
|
||||||
self.sd_check = self.peripherals.sd_check
|
self.sd_check = self.peripherals.sd_check
|
||||||
self.play_file = self.peripherals.play_file
|
self.play_file = self.peripherals.play_file
|
||||||
|
self.play_mp3_file = self.peripherals.play_mp3_file
|
||||||
self.stop_play = self.peripherals.stop_play
|
self.stop_play = self.peripherals.stop_play
|
||||||
self.volume = self.peripherals.volume
|
self.volume = self.peripherals.volume
|
||||||
self.audio_output = self.peripherals.audio_output
|
self.audio_output = self.peripherals.audio_output
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,7 @@ class Peripherals:
|
||||||
except OSError:
|
except OSError:
|
||||||
# sdcard init or mounting failed
|
# sdcard init or mounting failed
|
||||||
self._sd_mounted = False
|
self._sd_mounted = False
|
||||||
|
self._mp3_decoder = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def button1(self) -> bool:
|
def button1(self) -> bool:
|
||||||
|
|
@ -254,6 +255,18 @@ class Peripherals:
|
||||||
pass
|
pass
|
||||||
self.wavfile.close()
|
self.wavfile.close()
|
||||||
|
|
||||||
|
def play_mp3_file(self, filename):
|
||||||
|
if self._mp3_decoder is None:
|
||||||
|
from audiomp3 import MP3Decoder # noqa: PLC0415, import outside top-level
|
||||||
|
|
||||||
|
self._mp3_decoder = MP3Decoder(filename)
|
||||||
|
else:
|
||||||
|
self._mp3_decoder.open(filename)
|
||||||
|
|
||||||
|
self.audio.play(self._mp3_decoder)
|
||||||
|
while self.audio.playing:
|
||||||
|
pass
|
||||||
|
|
||||||
def stop_play(self):
|
def stop_play(self):
|
||||||
"""Stops playing a wav file."""
|
"""Stops playing a wav file."""
|
||||||
self.audio.stop()
|
self.audio.stop()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue