Skip to content

Commit 39ec280

Browse files
committed
allow filename for mp3decoder.file property
1 parent 639795c commit 39ec280

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

shared-bindings/audiomp3/MP3Decoder.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void check_for_deinit(audiomp3_mp3file_obj_t *self) {
139139
//|
140140
// Provided by context manager helper.
141141

142-
//| file: typing.BinaryIO
142+
//| file: Union[str, typing.BinaryIO] The name of a mp3 file (preferred) or an already opened mp3 file.
143143
//| """File to play back."""
144144
//|
145145
static mp_obj_t audiomp3_mp3file_obj_get_file(mp_obj_t self_in) {
@@ -152,6 +152,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiomp3_mp3file_get_file_obj, audiomp3_mp3file_obj_ge
152152
static mp_obj_t audiomp3_mp3file_obj_set_file(mp_obj_t self_in, mp_obj_t stream) {
153153
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
154154
check_for_deinit(self);
155+
if (mp_obj_is_str(stream)) {
156+
stream = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), stream, MP_ROM_QSTR(MP_QSTR_rb));
157+
}
155158
const mp_stream_p_t *stream_p = mp_get_stream_raise(stream, MP_STREAM_OP_READ);
156159

157160
if (stream_p->is_text) {

0 commit comments

Comments
 (0)