audioplayers
audioplayers copied to clipboard
`getDuration()` returns zero for Opus WebM codec
Checklist
- [X] I read the troubleshooting guide before raising this issue
- [X] I made sure that the issue I am raising doesn't already exist
Current bug behaviour
When calling audioPlayer.getDuration()
with an audiofile that's encoded with an Opus WebM codec, the method returns Duration.zero
.
I've tested on both Android and on Chrome, both of which support the Opus WebM codec.
On both platforms, the audio playback with audioplayers
works properly, just the duration is incorrect (it always returns Duration.zero
).
Expected behaviour
audioPlayer.getDuration()
returns the actual duration of the audio file.
Steps to reproduce
Run code sample with example URL provided below.
Code sample
Code sample
final audioPlayer = AudioPlayer();
await audioPlayer.setSourceUrl(url);
final duration = await audioPlayer.getDuration();
print(duration);
Affected platforms
Android, Windows
Platform details
- Platform 1: Chrome Version 114.0.5735.198 (Official Build) (arm64)
- Platform 2: Android version 13
AudioPlayers Version
main
Build mode
Debug mode.
Audio Files/URLs/Sources
https://firebasestorage.googleapis.com/v0/b/obedience-app.appspot.com/o/audio%2F9f4edbb3-34a0-4146-b7f7-85cca3640a3b.opus?alt=media&token=feed7a95-1dcb-4e93-924e-645539d82cef
Logs
No relevant logs.
Flutter doctor:
Output of: flutter doctor -v
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F82 darwin-arm64, locale
en-NL)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.2)
[✓] VS Code (version 1.80.1)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
Related issues / more information
No response
Working on PR
no way
See #1255. Some codecs are not supported on every platform
Hi @Gustl22 , I did check the supported codecs, and both Android and Chrome have support for this codec. There is also no problem playing the audio, there is only an issue with getting the duration of the audio file, which leads me to believe that this is a bug, rather than an issue with the codec not being supported.
On Chrome and Firefox, I can get the duration just fine: https://bluefireteam.github.io/audioplayers/
On Android, ineed, I don't get the duration, don't know if worth fixing, (or if it's even the fault of AudioPlayers). I'd rather work on an implementation of Exoplayer, see #1526
Alright. For now I chose to convert my audio files from WebM to a different format using a backend service, so this is no longer an issue for me.
I leave it open, as it's a valid snd reproducible bug. We either resolve it directly or wait for the Exoplayer implementation.
Alright. For now I chose to convert my audio files from WebM to a different format using a backend service, so this is no longer an issue for me.
@putnokiabel Is that the only solution you found? I am recording audio from the web where OpusWebM is my only choice to save it, I am not able to get the duration of the audio as well!
Alright. For now I chose to convert my audio files from WebM to a different format using a backend service, so this is no longer an issue for me.
@putnokiabel Is that the only solution you found? I am recording audio from the web where OpusWebM is my only choice to save it, I am not able to get the duration of the audio as well!
I haven't looked into other solutions since this one seemed to work for now. If converting to a different format is not an option because you need the files in WebM, you might consider using a web service or a different library to get the duration of the file (until this issue is fixed).
Same issue here. Is there any package worth trying to convert webm to mp3?