From ba2654a9436d514fdd78a0c02ebd8324011bd7dd Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak <dos@dosowisko.net> Date: Fri, 15 Sep 2023 21:52:44 +0200 Subject: [PATCH] audio_mp3: Report file position and duration The media framework allows the position and duration to use unspecified units, so do just that. It's better than nothing and it's already used by mp3_draw anyway. --- components/audio_mp3/audio_mp3.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/audio_mp3/audio_mp3.c b/components/audio_mp3/audio_mp3.c index b35bf8e63a..e7f06636d5 100644 --- a/components/audio_mp3/audio_mp3.c +++ b/components/audio_mp3/audio_mp3.c @@ -152,6 +152,12 @@ static void mp3_think(st3m_media *media, float ms_elapsed) { if (self->control.paused) return; + if (self->file) { + self->control.position = self->offset; + if (self->offset + 512 >= self->file_size) + self->control.position = self->file_size; + } + if (!self->started) { self->started = 1; mp3_think(media, 100); @@ -373,6 +379,6 @@ st3m_media *st3m_media_load_mp3(const char *path) { return NULL; } mp3dec_init(&self->mp3d); - self->control.duration = -1; + self->control.duration = self->file_size; return (st3m_media *)self; } -- GitLab