audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

`getDuration()` returns zero for Opus WebM codec

Open putnokiabel opened this issue 1 year ago • 8 comments

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

putnokiabel avatar Jul 22 '23 15:07 putnokiabel

See #1255. Some codecs are not supported on every platform

Gustl22 avatar Jul 31 '23 10:07 Gustl22

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.

putnokiabel avatar Jul 31 '23 19:07 putnokiabel

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

Gustl22 avatar Sep 11 '23 15:09 Gustl22

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 avatar Sep 12 '23 08:09 putnokiabel

I leave it open, as it's a valid snd reproducible bug. We either resolve it directly or wait for the Exoplayer implementation.

Gustl22 avatar Sep 25 '23 05:09 Gustl22

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!

dernoun avatar Jan 23 '24 23:01 dernoun

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).

putnokiabel avatar Jan 24 '24 09:01 putnokiabel

Same issue here. Is there any package worth trying to convert webm to mp3?

FaizanAhmad127 avatar Mar 09 '24 22:03 FaizanAhmad127