Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playbackState currentPosition not consistently updated #397

Closed
ReaganRealones opened this issue Jul 8, 2020 · 3 comments
Closed

playbackState currentPosition not consistently updated #397

ReaganRealones opened this issue Jul 8, 2020 · 3 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@ReaganRealones
Copy link

Which API doesn't behave as documented, and how does it misbehave?

Refer to the following piece of code for android,

AudioService.playbackStateStream.listen((event) {
      var position = event.currentPosition;
      print((position?.inSeconds?.toString()) ?? '0.0');
    });

What happens is that the position is updated as audio is playing(I am using just_audio), but after a few seconds, it stops printing the current position, like it could print 1,2,3,4 then maybe at around 8 it stops printing, but all this while the audio is playing. But what is weird is when u put the device in lock, then unlock it, or when u minimize the application and then reopen it, it will immediately print the time... For example, at first it would print 0,1,2,3,4,5, then maybe stop at 9, and hang there without printing anything, now when i minimize the app and then open it again, it will print 32 (Meaning the currentposition changes were just not being added to the stream). However again after some time, it will pause, then when you do the above, it continues...and so on.

Expected behavior
I expected that, it keeps printing the current position time without pausing and resuming after the triggers mentioned above

Runtime Environment (please complete the following information if relevant):

  • Device: [e.g. TECNO AB7]
  • OS: [e.g. Android 9.0.0]

Flutter SDK version

[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18363.900], locale en-UG)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[√] Android Studio (version 3.4)
[√] VS Code (version 1.46.1)
[√] Connected device (1 available)

• No issues found!
@ReaganRealones ReaganRealones added 1 backlog bug Something isn't working labels Jul 8, 2020
@ryanheise
Copy link
Owner

From what you've described, everything appears to be behaving exactly as documented.

AudioService.playbackStateStream emits exactly those events that you yourself have broadcast via AudioServiceBackground.setState which says on its documentation page:

/// The playback [position] should be explicitly updated only when the normal
/// continuity of time is disrupted, such as when the user performs a seek,
/// or buffering occurs, etc. Thus, the [position] parameter indicates the
/// playback position at the time the state was updated while the
/// [updateTime] parameter indicates the precise time of that update.

PlaybackState.currentPosition is a convenience method that computes where the current position would be based on the last update time and position (adding to it the amount of time that has elapsed since the last update time), but this is NOT a stream, so it will not emit continuous values. It is just a plain old value that you need to query repeatedly to see it change. Although you may if you wish create a stream that queries this value periodically. Only, that is not the purpose of the playbackStateStream which only reports state changes emitted through setState.

If you still think this is not behaving as per the documentation, I will need you to complete the bug report fully, including a minimal reproduction project, and contrast the behaviour you're observing with what the documentation says should happen.

@ReaganRealones
Copy link
Author

Ohhhh, thank you for that clear explanation, everything makes sense now. I will close this now.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants