Struct mpris::ProgressTracker
[−]
[src]
pub struct ProgressTracker<'a> { /* fields omitted */ }
Controller for calculating Progress for a given Player.
Call the tick
method to get the most current Progress data.
Methods
impl<'a> ProgressTracker<'a>
[src]
fn new(player: &'a Player<'a>, interval_ms: u32) -> Result<Self, DBusError>
[src]
Construct a new ProgressTracker for the provided Player.
The interval_ms
value is the desired time between ticks when calling the tick
method.
See tick
for more information about that.
You probably want to use Player::track_progress
instead of this method.
Errors
Returns an error in case Player metadata or state retrieval over DBus fails.
fn tick(&mut self) -> (&Progress, bool)
[src]
Returns a (Progress
, bool
) pair at each interval, or as close to each interval as
possible.
The bool
is true
if the Progress
was refreshed, or false
if the old Progress
was
reused.
If there is time left until the next interval window, then the tracker will process DBus
events to determine if something changed (and potentially perform a full refresh). If there
is no time left, then the previous Progress
will be returned again.
If refreshing failed for some reason the old Progress
will be returned.
It is recommended to call this inside a loop to maintain your progress display.
On reusing Progress
instances
Progress
can be reused until something about the player changes, like track or playback
status. As long as nothing changes, Progress
can accurately determine playback position
from timing data.
You can use the returned bool
in order to perform similar optimizations yourself, as a
false
value means that nothing (except potentially position
) changed.
Examples
Simple progress tracker:
// Refresh every 100ms let mut progress_tracker = player.track_progress(100).unwrap(); loop { let (progress, _) = progress_tracker.tick(); update_progress_bar(progress.position()); }
Using the was_refreshed
bool
:
// Refresh every 100ms let mut progress_tracker = player.track_progress(100).unwrap(); loop { let (progress, was_changed) = progress_tracker.tick(); if was_changed { update_track_title(progress.metadata().title()); reset_progress_bar(progress.position(), progress.length()); } else { update_progress_bar(progress.position()); } }
fn force_refresh(&mut self) -> Result<(), DBusError>
[src]
Force a refresh right now.
This will ignore the interval and perform a refresh anyway, storing the result as the last
Progress
value.
Errors
Returns an error if the refresh failed.