Skip to main content

SharedPlayerState

Struct SharedPlayerState 

Source
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§

Source§

impl SharedPlayerState

Source

pub fn new() -> Arc<Self>

Source

pub fn playback_state(&self) -> PlaybackState

Source

pub fn set_playback_state(&self, state: PlaybackState)

Source

pub fn position_ms(&self) -> u64

Source

pub fn set_position_ms(&self, pos: u64)

Source

pub fn track_info(&self) -> Option<TrackInfo>

Source

pub fn set_track_info(&self, info: Option<TrackInfo>)

Source

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.

Source

pub fn bump_generation(&self) -> u64

Source

pub fn generation(&self) -> u64

Source

pub fn request_quit(&self)

Source

pub fn quit_requested(&self) -> bool

Source

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.

Source

pub fn take_metadata_refresh(&self) -> bool

Returns true and clears the flag if a metadata refresh is pending.

Source

pub fn radio_mode(&self) -> bool

Source

pub fn set_radio_mode(&self, enabled: bool)

Source

pub fn playlist_version(&self) -> u64

Source

pub fn add_items(&self, items: Vec<PlaylistItem>)

Append items to the playlist.

Source

pub fn insert_items_after(&self, items: Vec<PlaylistItem>, after: QueueItemId)

Insert items after a specific queue item.

Source

pub fn update_paths(&self, updates: &[(QueueItemId, PathBuf)])

Update file paths for playlist items (after organize moves files).

Source

pub fn remove_item(&self, id: QueueItemId)

Remove an item by ID.

Source

pub fn move_item(&self, id: QueueItemId, target: QueueItemId, after: bool)

Move an item relative to another entry.

Source

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.

Source

pub fn set_cursor(&self, id: Option<QueueItemId>)

Set the cursor (what’s playing / should play).

Source

pub fn cursor(&self) -> Option<QueueItemId>

Get the current cursor ID.

Source

pub fn clear_playlist(&self)

Clear the entire playlist + cursor.

Source

pub fn advance_cursor(&self) -> Option<(QueueItemId, PathBuf)>

Advance cursor to the next Ready item. Returns (id, path) if found. Moves the cursor. Used for explicit next-track commands.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn is_cursor(&self, id: QueueItemId) -> bool

Check if the cursor is on the given item.

Source

pub fn snapshot_playlist(&self) -> (Vec<PlaylistItem>, Option<QueueItemId>)

Get the full playlist snapshot (items + cursor) for undo of ClearPlaylist.

Source

pub fn get_item(&self, id: QueueItemId) -> Option<PlaylistItem>

Get an item by ID (for undo of RemoveFromPlaylist).

Source

pub fn item_before(&self, id: QueueItemId) -> Option<QueueItemId>

Get the ID of the item immediately before the given ID (None if first).

Source

pub fn items_before( &self, ids: &[QueueItemId], ) -> Vec<(QueueItemId, Option<QueueItemId>)>

For each ID, get the ID of the item before it (or None if first). Used to snapshot positions before a batch move for undo.

Source

pub fn restore_playlist( &self, items: Vec<PlaylistItem>, cursor: Option<QueueItemId>, )

Restore a full playlist from snapshot (for redo of ClearPlaylist undo).

Source

pub fn remove_items(&self, ids: &[QueueItemId])

Remove multiple items by IDs.

Source

pub fn insert_item_at(&self, item: PlaylistItem, after: Option<QueueItemId>)

Insert a single item after a given ID (or at front if None).

Source

pub fn move_item_to(&self, id: QueueItemId, after: Option<QueueItemId>)

Move a single item to after after (or to front if None).

Source

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.

Source

pub fn derive_visible_queue(&self) -> VisibleQueueSnapshot

Derive the visible queue from the playlist + cursor. O(n). Called once per UI tick.

Trait Implementations§

Source§

impl Debug for SharedPlayerState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,