just_audio
just_audio copied to clipboard
value from positionStream greater than duration
Which API doesn't behave as documented, and how does it misbehave? positionStream produce last value that greater than track duration
Minimal reproduction project https://github.com/johnny-byte/just_audio/blob/minor/just_audio/example/lib/main.dart
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
- Seek to end
Error messages
Expected behavior positionStream should produce last value that less or equal than track duration
Screenshots
https://user-images.githubusercontent.com/52435334/180467150-644d0ad4-4a12-4984-9e9d-ae4dfa46eab6.mp4
Desktop (please complete the following information):
Smartphone (please complete the following information):
- Device: Pixel 4
- OS: Android 10.0
Flutter SDK version
[✓] Flutter (Channel stable, 3.0.4, on Ubuntu 20.04.4 LTS 5.15.0-41-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.2)
[✓] Android Studio
[✓] VS Code (version 1.58.2)
[✓] VS Code
[✓] Connected device (1 available)
[✓] HTTP Host Availability
! Doctor found issues in 1 categories.
Additional context
Thanks for the report. The position could/should probably be clipped with min(position, duration)
but only where the duration is actually known. I would also point out that the duration is not necessarily correct, it is just the duration that is reported by the audio file's metadata, however it's still a good idea to clip one to the other.
Note: in the meantime, you can also do that clipping yourself in your app by calling min(position, duration)
.
I think it's related to #802, because provided sample code is using streamed file.
i'm also facing same issue ,positionStream value is receiving greater than total duration
used plugin version just_audio: ^0.9.28
Hi @johnny-byte , I have checked the code and actually it already implements this clipping, so the position should not exceed the duration.
So there is no bug in positionStream
, but it is true that with the way the example combines the position and duration streams, it doesn't care about clipping the position after combining the streams:
/// Collects the data useful for displaying in a seek bar, using a handy
/// feature of rx_dart to combine the 3 streams of interest into one.
Stream<PositionData> get _positionDataStream =>
Rx.combineLatest3<Duration, Duration, Duration?, PositionData>(
_player.positionStream,
_player.bufferedPositionStream,
_player.durationStream,
(position, bufferedPosition, duration) => PositionData(
position, bufferedPosition, duration ?? Duration.zero));
If you have copied that example code into your own app, you might want to change ti so that it clips the position to the duration.
I am experiencing the same issue using a local file on iOS. The position is exceeding the duration by 100-200ms.