Skip to content

Commit c291a02

Browse files
authored
Merge pull request micropython#6943 from snkYmkrct/main
Support for opening a file by name in MP3Decoder
2 parents de80db6 + d7ea1c3 commit c291a02

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

shared-bindings/audiomp3/MP3Decoder.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ STATIC mp_obj_t audiomp3_mp3file_obj_set_file(mp_obj_t self_in, mp_obj_t file) {
172172
}
173173
MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_set_file_obj, audiomp3_mp3file_obj_set_file);
174174

175+
//| def open(self, filepath: str) -> None:
176+
//| """Takes in the name of a mp3 file, opens it, and replaces the old playback file."""
177+
//| ...
178+
//|
179+
STATIC mp_obj_t audiomp3_mp3file_obj_open(mp_obj_t self_in, mp_obj_t path) {
180+
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
181+
check_for_deinit(self);
182+
183+
mp_obj_t file = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), path, MP_ROM_QSTR(MP_QSTR_rb));
184+
185+
common_hal_audiomp3_mp3file_set_file(self, file);
186+
return mp_const_none;
187+
}
188+
MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_open_obj, audiomp3_mp3file_obj_open);
189+
175190
MP_PROPERTY_GETSET(audiomp3_mp3file_file_obj,
176191
(mp_obj_t)&audiomp3_mp3file_get_file_obj,
177192
(mp_obj_t)&audiomp3_mp3file_set_file_obj);
@@ -256,6 +271,7 @@ MP_PROPERTY_GETTER(audiomp3_mp3file_samples_decoded_obj,
256271

257272
STATIC const mp_rom_map_elem_t audiomp3_mp3file_locals_dict_table[] = {
258273
// Methods
274+
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&audiomp3_mp3file_open_obj) },
259275
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiomp3_mp3file_deinit_obj) },
260276
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
261277
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiomp3_mp3file___exit___obj) },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy