diff --git a/internal_filesystem/apps/com.micropythonos.musicplayer/assets/audio_player.py b/internal_filesystem/apps/com.micropythonos.musicplayer/assets/audio_player.py index 0975fd6d..08b7195a 100644 --- a/internal_filesystem/apps/com.micropythonos.musicplayer/assets/audio_player.py +++ b/internal_filesystem/apps/com.micropythonos.musicplayer/assets/audio_player.py @@ -11,6 +11,7 @@ class AudioPlayer: # class-level defaults (shared by every instance) _i2s = None # the I2S object (created once per playback) _volume = 50 # 0-100 (100 = full scale) + _keep_running = True @staticmethod def find_data_chunk(f): @@ -67,11 +68,17 @@ class AudioPlayer: """Return current volume 0-100.""" return cls._volume + #@classmethod + def stop_playing(): + print("stop_playing()") + AudioPlayer._keep_running = False + # ------------------------------------------------------------------ # Playback entry point (called from a thread) # ------------------------------------------------------------------ @classmethod def play_wav(cls, filename): + AudioPlayer._keep_running = True """Play a large mono 16-bit PCM WAV file with on-the-fly volume.""" try: with open(filename, 'rb') as f: @@ -124,6 +131,11 @@ class AudioPlayer: total = 0 while total < data_size: + if total % 51 == 0: + print('.', end='') + if not AudioPlayer._keep_running: + print("_keep_running = False, stopping...") + break to_read = min(chunk_size, data_size - total) raw = bytearray(f.read(to_read)) # mutable for in-place scaling if not raw: diff --git a/internal_filesystem/apps/com.micropythonos.musicplayer/assets/music_player.py b/internal_filesystem/apps/com.micropythonos.musicplayer/assets/music_player.py index 8cbf7123..0bb69fcf 100644 --- a/internal_filesystem/apps/com.micropythonos.musicplayer/assets/music_player.py +++ b/internal_filesystem/apps/com.micropythonos.musicplayer/assets/music_player.py @@ -1,6 +1,7 @@ import machine import os import _thread +import time from mpos.apps import Activity, Intent import mpos.sdcard @@ -90,6 +91,8 @@ class FullscreenPlayer(Activity): print("Not playing any file...") else: print("Starting thread to play file {self._filename}") + AudioPlayer.stop_playing() + time.sleep(1) _thread.stack_size(mpos.apps.good_stack_size()) _thread.start_new_thread(AudioPlayer.play_wav, (self._filename,))