audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

getDuration is returning zero in release mode

Open MilesAdamson opened this issue 2 years ago • 1 comments

    _audioPlayer = await AudioCache().play("song.mp3);
    _audioDurationMS = await _audioPlayer.getDuration();
    print(_audioDurationMS);

The above prints this in debug mode:

I/flutter (31709): 110132

And this in release mode:

I/flutter (31832): 0

If I add a super hacky delay, it works in release mode

    _audioPlayer = await AudioCache().play(filename);

    // HACK ALERT
    await Future.delayed(const Duration(milliseconds: 200));
    
    _audioDurationMS = await _audioPlayer.getDuration();
    print(_audioDurationMS);
I/flutter (31970): 110132

Platform: Pixel 4 XL api 31

MilesAdamson avatar Dec 15 '21 22:12 MilesAdamson

Any updates on this, I'm also getting this on my pixel 4 device in release mode, _audioPlayer.getDuration(); is always returning zero.

AraKurghinyan avatar Jul 13 '22 08:07 AraKurghinyan

Did you test on audioplayers: ^1.x.x ? See also #1033

Gustl22 avatar Sep 27 '22 16:09 Gustl22

I've just tested this on 1.1.0 audioplayers. Still observing issue

Trying to play AAC in m4a container. Randomly duration can be null, but may be not. In debug mode works stable.

nikitatg avatar Sep 28 '22 09:09 nikitatg

@nikitatg did you add the Internet permissions to the AndroidManifest.xml? Also can you verify / reproduce with our example? Or does it work with an AssetSource?

Gustl22 avatar Apr 24 '23 11:04 Gustl22

@nikitatg did you add the Internet permissions to the AndroidManifest.xml? Also can you verify / reproduce with our example? Or does it work with an AssetSource?

Forgot to mention that it happening on desktop platforms: Ubuntu 20 and Windows 10

nikitatg avatar Apr 24 '23 12:04 nikitatg

@Gustl22 for now on yourth example project (with audioplayers v 4.0.1) I see no that issue (Windows platform). For test was used records from android flutter dictaphone (based on package "record"). I will try 4.0.1 on my main project soon

nikitatg avatar Apr 25 '23 06:04 nikitatg

~~I'd like the confirm that this is still happening in v4.01 and v5.0.0 on Linux. I have a similar pattern:~~

await player.setSource(DeviceFileSource(musicPath));
final Duration? dur = await player.getDuration();

~~One third of the time I'm getting the actual duration of my MP3. Another third of the time I'm getting a duration of 0. And another third of the time dur is being set to null.~~

Sorry, I had some improperly structured async code that was causing a false alarm with my app on Linux. my apologies.

define-private-public avatar Jul 27 '23 03:07 define-private-public

This issue is about a version prior 1.x.x. So I'm closing it. It's also very likely that it is the same as #1494 This issue also only is about Android.

Gustl22 avatar Jul 31 '23 10:07 Gustl22