Skip to content

Commit 08211b7

Browse files
Music Player: play in thread
1 parent d149883 commit 08211b7

File tree

1 file changed

+13
-11
lines changed
  • internal_filesystem/apps/com.micropythonos.musicplayer/assets

1 file changed

+13
-11
lines changed

internal_filesystem/apps/com.micropythonos.musicplayer/assets/music_player.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import machine
2+
import uos
3+
import _thread
4+
15
from mpos.apps import Activity
26
import mpos.sdcard
37
import mpos.ui
4-
# play music
5-
import machine
6-
import uos
7-
from machine import I2S, Pin
88

99
class MusicPlayer(Activity):
1010

@@ -37,7 +37,9 @@ def file_explorer_event_cb(self, event):
3737
fullpath = f"{clean_path}{file}"
3838
print(f"Selected: {fullpath}")
3939
if fullpath.lower().endswith('.wav'):
40-
self.play_wav(fullpath)
40+
_thread.stack_size(mpos.apps.good_stack_size())
41+
_thread.start_new_thread(self.play_wav, (fullpath,))
42+
#self.play_wav(fullpath)
4143
else:
4244
print("INFO: ignoring unsupported file format")
4345

@@ -68,13 +70,13 @@ def play_wav(self, filename):
6870
raise ValueError("Only mono audio supported (convert with -ac 1 in FFmpeg)")
6971

7072
# Configure I2S (TX mode for output)
71-
i2s = I2S(0, # I2S peripheral 0
72-
sck=Pin(2, Pin.OUT), # BCK
73-
ws=Pin(47, Pin.OUT), # LRCK
74-
sd=Pin(16, Pin.OUT), # DIN
75-
mode=I2S.TX,
73+
i2s = machine.I2S(0, # I2S peripheral 0
74+
sck=machine.Pin(2, machine.Pin.OUT), # BCK
75+
ws=machine.Pin(47, machine.Pin.OUT), # LRCK
76+
sd=machine.Pin(16, machine.Pin.OUT), # DIN
77+
mode=machine.I2S.TX,
7678
bits=16,
77-
format=I2S.MONO,
79+
format=machine.I2S.MONO,
7880
rate=sample_rate,
7981
ibuf=16000) # Internal buffer size (adjust if audio stutters)
8082

0 commit comments

Comments
 (0)