pub struct SharedPlayerState { /* private fields */ }Expand description
Shared player state — atomics for lock-free reads from UI thread.
The engine writes these, the UI reads them. No mutexes in the hot path.
Implementations§
pub fn new() -> Arc<Self> ⓘ
pub fn playback_state(&self) -> PlaybackState
pub fn set_playback_state(&self, state: PlaybackState)
pub fn position_ms(&self) -> u64
pub fn set_position_ms(&self, pos: u64)
pub fn track_info(&self) -> Option<TrackInfo>
pub fn set_track_info(&self, info: Option<TrackInfo>)
Sourcepub fn current_download_fraction(&self) -> Option<f64>
pub fn current_download_fraction(&self) -> Option<f64>
Download fraction (0.0..1.0) for the currently playing track, if streaming.
Returns None for fully-downloaded or non-playing tracks.
pub fn request_quit(&self)
pub fn quit_requested(&self) -> bool
Sourcepub fn signal_metadata_refresh(&self)
pub fn signal_metadata_refresh(&self)
Signal that metadata has been refreshed mid-stream (e.g. download completed).
The UI loop calls take_metadata_refresh() to consume this flag and
force a souvlaki/cover-art update without waiting for a track change.
Sourcepub fn take_metadata_refresh(&self) -> bool
pub fn take_metadata_refresh(&self) -> bool
Returns true and clears the flag if a metadata refresh is pending.
pub fn radio_mode(&self) -> bool
pub fn set_radio_mode(&self, enabled: bool)
Sourcepub fn output_sample_rate(&self) -> Option<u32>
pub fn output_sample_rate(&self) -> Option<u32>
None until a track has started and the device rate is known.
pub fn set_output_sample_rate(&self, rate: u32)
Sourcepub fn clear_output_sample_rate(&self)
pub fn clear_output_sample_rate(&self)
Back to “not known yet”, for the window where the device is between rates. A switch takes as long as the hardware needs to reclock — the better part of a second on USB — and the previous track’s rate is not an answer for this one.
pub fn playlist_version(&self) -> u64
Sourcepub fn add_items(&self, items: Vec<PlaylistItem>)
pub fn add_items(&self, items: Vec<PlaylistItem>)
Append items to the playlist.
Sourcepub fn insert_items_after(&self, items: Vec<PlaylistItem>, after: QueueItemId)
pub fn insert_items_after(&self, items: Vec<PlaylistItem>, after: QueueItemId)
Insert items after a specific queue item.
Sourcepub fn update_paths(&self, updates: &[(QueueItemId, PathBuf)])
pub fn update_paths(&self, updates: &[(QueueItemId, PathBuf)])
Update file paths for playlist items (after organize moves files).
Sourcepub fn remove_item(&self, id: QueueItemId)
pub fn remove_item(&self, id: QueueItemId)
Remove an item by ID.
Sourcepub fn move_item(&self, id: QueueItemId, target: QueueItemId, after: bool)
pub fn move_item(&self, id: QueueItemId, target: QueueItemId, after: bool)
Move an item relative to another entry.
Sourcepub fn move_items(&self, ids: &[QueueItemId], target: QueueItemId, after: bool)
pub fn move_items(&self, ids: &[QueueItemId], target: QueueItemId, after: bool)
Batch move: extract items by ID, reinsert them at target position.
Preserves the relative order of the moved items.
Sourcepub fn set_cursor(&self, id: Option<QueueItemId>)
pub fn set_cursor(&self, id: Option<QueueItemId>)
Set the cursor (what’s playing / should play).
Sourcepub fn cursor(&self) -> Option<QueueItemId>
pub fn cursor(&self) -> Option<QueueItemId>
Get the current cursor ID.
Sourcepub fn clear_playlist(&self)
pub fn clear_playlist(&self)
Clear the entire playlist + cursor.
Sourcepub fn advance_cursor_loadable(&self) -> Option<QueueItemId>
pub fn advance_cursor_loadable(&self) -> Option<QueueItemId>
Move the cursor to the next item that can still play — the first item
after the cursor that is not Failed — and return its ID.
An item that is still downloading parks the cursor rather than being skipped, so playback resumes from it when its data lands. Skipping it would drop it from the queue for good.
With no cursor set, starts from the top. A cursor pointing at an item
that is no longer in the playlist yields None — restarting from the
top would silently replay the queue.
Sourcepub fn peek_next_ready_after(
&self,
after_id: QueueItemId,
) -> Option<(QueueItemId, PathBuf)>
pub fn peek_next_ready_after( &self, after_id: QueueItemId, ) -> Option<(QueueItemId, PathBuf)>
Peek at the next Ready item after a given item ID WITHOUT moving the cursor. Used by the decode thread for gapless lookahead — the cursor is moved later by update_playback_state when playback actually reaches the track.
Sourcepub fn retreat_cursor(&self) -> Option<(QueueItemId, PathBuf)>
pub fn retreat_cursor(&self) -> Option<(QueueItemId, PathBuf)>
Retreat cursor to the previous item. Returns (id, path) if found. For prev_track — goes to the item before cursor regardless of load state.
Sourcepub fn update_load_state(&self, id: QueueItemId, new_state: LoadState)
pub fn update_load_state(&self, id: QueueItemId, new_state: LoadState)
Update the load state of a playlist item. Safe — just a field update under lock.
Sourcepub fn update_item_metadata(
&self,
id: QueueItemId,
title: String,
artist: String,
album_artist: String,
album: String,
duration_ms: Option<u64>,
)
pub fn update_item_metadata( &self, id: QueueItemId, title: String, artist: String, album_artist: String, album: String, duration_ms: Option<u64>, )
Update playlist item metadata after a full download completes. Used for progressive enhancement: streaming started with partial Symphonia tags, now the full file is available so we can refresh with complete lofty metadata.
Sourcepub fn item_playback_source(&self, id: QueueItemId) -> Option<PlaybackSource>
pub fn item_playback_source(&self, id: QueueItemId) -> Option<PlaybackSource>
Get the playback source for an item if it’s ready to play.
Returns None if not enough data is available yet.
Sourcepub fn item_path_if_ready(&self, id: QueueItemId) -> Option<PathBuf>
pub fn item_path_if_ready(&self, id: QueueItemId) -> Option<PathBuf>
Get the path of an item if it’s Ready (legacy convenience — use item_playback_source for streaming).
Sourcepub fn is_cursor(&self, id: QueueItemId) -> bool
pub fn is_cursor(&self, id: QueueItemId) -> bool
Check if the cursor is on the given item.
Sourcepub fn same_album_item_ids(&self, id: QueueItemId) -> Vec<QueueItemId>
pub fn same_album_item_ids(&self, id: QueueItemId) -> Vec<QueueItemId>
Get QueueItemIds of all playlist items sharing the same album as the given item. Matches on both album name and album artist to avoid false positives (e.g. two different “Greatest Hits” by different artists).
Sourcepub fn pending_downloads(&self) -> Vec<(i64, QueueItemId)>
pub fn pending_downloads(&self) -> Vec<(i64, QueueItemId)>
Get all playlist items that are Pending and have a db_id.
Returns (db_id, QueueItemId) pairs suitable for the download queue.
Sourcepub fn downloads_in_flight(&self) -> Vec<(QueueItemId, u64, u64)>
pub fn downloads_in_flight(&self) -> Vec<(QueueItemId, u64, u64)>
Every item mid-transfer, with the bytes it has and the bytes it expects.
Progress moves without the playlist version moving — the download thread writes the byte counter directly — so anything following the version alone shows a frozen bar. This is how a watcher sees it move.
Sourcepub fn item_db_id(&self, id: QueueItemId) -> Option<i64>
pub fn item_db_id(&self, id: QueueItemId) -> Option<i64>
Get the db_id for a specific playlist item.
Sourcepub fn item_load_state(&self, id: QueueItemId) -> Option<LoadState>
pub fn item_load_state(&self, id: QueueItemId) -> Option<LoadState>
Get the load state of a specific playlist item.
Sourcepub fn snapshot_playlist(&self) -> (Vec<PlaylistItem>, Option<QueueItemId>)
pub fn snapshot_playlist(&self) -> (Vec<PlaylistItem>, Option<QueueItemId>)
Get the full playlist snapshot (items + cursor) for undo of ClearPlaylist.
Sourcepub fn get_item(&self, id: QueueItemId) -> Option<PlaylistItem>
pub fn get_item(&self, id: QueueItemId) -> Option<PlaylistItem>
Get an item by ID (for undo of RemoveFromPlaylist).
Sourcepub fn item_before(&self, id: QueueItemId) -> Option<QueueItemId>
pub fn item_before(&self, id: QueueItemId) -> Option<QueueItemId>
Get the ID of the item immediately before the given ID (None if first).
Sourcepub fn reorder_to(&self, order: &[QueueItemId])
pub fn reorder_to(&self, order: &[QueueItemId])
For each ID, the ID of the item before it (or None if first), returned in
playlist order regardless of the order ids arrives in.
Undo replays these left to right, so an item whose recorded predecessor is
also in ids must come after it — otherwise the predecessor is missing at
replay time and the item lands at the end of the playlist instead.
Put the items in exactly this order.
Items not named keep their relative order and follow at the end, so a stale order cannot lose anything. The items themselves are moved, not rebuilt: their ids, load states and download progress are what the rest of the player is holding on to.
pub fn items_before( &self, ids: &[QueueItemId], ) -> Vec<(QueueItemId, Option<QueueItemId>)>
Sourcepub fn surviving_item_before(
&self,
id: QueueItemId,
removed: &[QueueItemId],
) -> Option<QueueItemId>
pub fn surviving_item_before( &self, id: QueueItemId, removed: &[QueueItemId], ) -> Option<QueueItemId>
The nearest item before id that is not itself being removed — where
playback resumes from after a batch delete that takes out the cursor.
None means resume from the top of what survives.
Sourcepub fn restore_playlist(
&self,
items: Vec<PlaylistItem>,
cursor: Option<QueueItemId>,
)
pub fn restore_playlist( &self, items: Vec<PlaylistItem>, cursor: Option<QueueItemId>, )
Restore a full playlist from snapshot (for redo of ClearPlaylist undo).
Sourcepub fn remove_items(&self, ids: &[QueueItemId])
pub fn remove_items(&self, ids: &[QueueItemId])
Remove multiple items by IDs.
Sourcepub fn insert_item_at(&self, item: PlaylistItem, after: Option<QueueItemId>)
pub fn insert_item_at(&self, item: PlaylistItem, after: Option<QueueItemId>)
Insert a single item after a given ID (or at front if None).
Sourcepub fn move_item_to(&self, id: QueueItemId, after: Option<QueueItemId>)
pub fn move_item_to(&self, id: QueueItemId, after: Option<QueueItemId>)
Move a single item to after after (or to front if None).
Sourcepub fn move_items_to(&self, entries: &[(QueueItemId, Option<QueueItemId>)])
pub fn move_items_to(&self, entries: &[(QueueItemId, Option<QueueItemId>)])
Batch move: reposition each item to after its given predecessor. Processes in order so earlier insertions don’t corrupt later positions.
Sourcepub fn derive_visible_queue(&self) -> VisibleQueueSnapshot
pub fn derive_visible_queue(&self) -> VisibleQueueSnapshot
Derive the visible queue from the playlist + cursor. O(n). Called once per UI tick.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);