Skip to main content

AsyncPreviewPlayer

Struct AsyncPreviewPlayer 

Source
pub struct AsyncPreviewPlayer { /* private fields */ }
Expand description

Async wrapper around PlayerHandle.

On creation, a spawn_blocking thread opens the file, splits the player, and starts the runner. All control methods delegate directly to the underlying PlayerHandle — no inner Mutex.

§Usage

use ff_preview::AsyncPreviewPlayer;
use std::time::Duration;

let player = AsyncPreviewPlayer::open("clip.mp4").await?;
player.play();
player.seek(Duration::from_secs(30));
while let Some(event) = player.next_event().await { ... }

Implementations§

Source§

impl AsyncPreviewPlayer

Source

pub async fn open( path: impl AsRef<Path> + Send + 'static, ) -> Result<Self, PreviewError>

Open a media file asynchronously.

File I/O and codec initialisation run on a spawn_blocking thread. The runner is also started on a dedicated blocking thread and runs until stop is called or EOF is reached.

§Errors

Returns PreviewError if the file is missing, unreadable, or contains neither a video nor an audio stream.

Source

pub fn play(&self)

Resume playback.

Source

pub fn pause(&self)

Pause playback.

Source

pub fn stop(&self)

Stop the presentation loop.

Source

pub fn seek(&self, pts: Duration)

Seek to pts.

Source

pub fn set_rate(&self, rate: f64)

Set the playback rate.

Source

pub fn current_pts(&self) -> Duration

PTS of the most recently presented frame.

Source

pub fn duration(&self) -> Option<Duration>

Container-reported duration, or None for live / streaming sources.

Source

pub fn pop_audio_samples(&self, n: usize) -> Vec<f32>

Pull up to n interleaved stereo f32 PCM samples at 48 kHz.

Source

pub fn poll_event(&self) -> Option<PlayerEvent>

Poll for the next PlayerEvent without blocking.

Returns None when no events are pending.

Source

pub async fn next_event(&self) -> Option<PlayerEvent>

Await the next PlayerEvent.

Blocks in a spawn_blocking thread until an event arrives or the channel is closed. Returns None when the runner has exited.

Trait Implementations§

Source§

impl Clone for AsyncPreviewPlayer

Source§

fn clone(&self) -> AsyncPreviewPlayer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for AsyncPreviewPlayer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.