Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdd2af0

Browse files
Music Player: improve used feedback
1 parentb2329aa commitcdd2af0

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

‎internal_filesystem/apps/com.micropythonos.musicplayer/assets/audio_player.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ----------------------------------------------------------------------
1212
classAudioPlayer:
1313
_i2s=None
14-
_volume=50# 0-100
14+
_volume=50# 0-100
1515
_keep_running=True
1616

1717
# ------------------------------------------------------------------
@@ -22,10 +22,10 @@ def find_data_chunk(f):
2222
"""Return (data_start, data_size, sample_rate, channels, bits_per_sample)"""
2323
f.seek(0)
2424
iff.read(4)!=b'RIFF':
25-
raiseValueError("Not a RIFF file")
25+
raiseValueError("Not a RIFF(standard .wav)file")
2626
file_size=int.from_bytes(f.read(4),'little')+8
2727
iff.read(4)!=b'WAVE':
28-
raiseValueError("Not a WAVE file")
28+
raiseValueError("Not a WAVE(standard .wav)file")
2929

3030
pos=12
3131
sample_rate=None
@@ -154,7 +154,7 @@ def _convert_32_to_16(buf: bytearray) -> bytearray:
154154
# Main playback routine
155155
# ------------------------------------------------------------------
156156
@classmethod
157-
defplay_wav(cls,filename):
157+
defplay_wav(cls,filename,result_callback=None):
158158
cls._keep_running=True
159159
try:
160160
withopen(filename,'rb')asf:
@@ -265,9 +265,13 @@ def scale_audio(buf: ptr8, num_bytes: int, scale_fixed: int):
265265

266266
total_original+=to_read
267267

268-
print("Playback finished.")
268+
print(f"Finished playing{filename}")
269+
ifresult_callback:
270+
result_callback(f"Finished playing{filename}")
269271
exceptExceptionase:
270-
print(f"AudioPlayer error:{e}")
272+
print(f"Error:{e}\nwhile playing{filename}")
273+
ifresult_callback:
274+
result_callback(f"Error:{e}\nwhile playing{filename}")
271275
finally:
272276
ifcls._i2s:
273277
cls._i2s.deinit()

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def file_explorer_event_cb(self, event):
3939
file=self.file_explorer.explorer_get_selected_file_name()
4040
fullpath=f"{clean_path}{file}"
4141
print(f"Selected:{fullpath}")
42-
iffullpath.lower().endswith('.wav'):
43-
self.destination=FullscreenPlayer
44-
self.startActivity(Intent(activity_class=FullscreenPlayer).putExtra("filename",fullpath))
45-
else:
46-
print("INFO: ignoring unsupported file format")
42+
#if fullpath.lower().endswith('.wav'):
43+
self.destination=FullscreenPlayer
44+
self.startActivity(Intent(activity_class=FullscreenPlayer).putExtra("filename",fullpath))
45+
#else:
46+
# print("INFO: ignoring unsupported file format")
4747

4848
classFullscreenPlayer(Activity):
4949
# No __init__() so super.__init__() will be called automatically
@@ -101,7 +101,7 @@ def onResume(self, screen):
101101
AudioPlayer.stop_playing()
102102
time.sleep(0.1)
103103
_thread.stack_size(mpos.apps.good_stack_size())
104-
_thread.start_new_thread(AudioPlayer.play_wav, (self._filename,))
104+
_thread.start_new_thread(AudioPlayer.play_wav, (self._filename,self.player_finished,))
105105

106106
deffocus_obj(self,obj):
107107
obj.set_style_border_color(lv.theme_get_color_primary(None),lv.PART.MAIN)
@@ -113,3 +113,10 @@ def defocus_obj(self, obj):
113113
defstop_button_clicked(self,event):
114114
AudioPlayer.stop_playing()
115115
self.finish()
116+
117+
defplayer_finished(self,result=None):
118+
text=f"Finished playing{self._filename}"
119+
ifresult:
120+
text=result
121+
print(f"AudioPlayer finished:{text}")
122+
lv.async_call(lambdal:self._filename_label.set_text(text),None)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp