Skip to main content

kithara_play/player/
view.rs

1use crate::bridge::PlaybackSnapshot;
2
3/// One coherent view of a player's live playback state.
4///
5/// Each field preserves its own unknown state. Decorators may refine the raw
6/// player position while keeping the other fields from the same snapshot.
7#[derive(Clone, Copy, Debug, Default, PartialEq)]
8#[non_exhaustive]
9pub struct PlaybackView {
10    /// Seconds playable without further network access.
11    pub buffered: Option<f64>,
12    /// Total media duration in seconds; `None` while unknown.
13    pub duration: Option<f64>,
14    /// Playback position in seconds; `None` until a stable value exists.
15    pub position: Option<f64>,
16    /// Whether playback is active.
17    pub playing: bool,
18}
19
20impl From<PlaybackSnapshot> for PlaybackView {
21    fn from(snapshot: PlaybackSnapshot) -> Self {
22        Self {
23            position: Some(snapshot.position()),
24            duration: (snapshot.duration() > 0.0).then_some(snapshot.duration()),
25            buffered: Some(snapshot.frontier().max(snapshot.cached())),
26            playing: snapshot.is_playing(),
27        }
28    }
29}