Struct egui_video::Player

source ·
pub struct Player {
    pub video_streamer: Arc<Mutex<VideoStreamer>>,
    pub audio_streamer: Option<Arc<Mutex<AudioStreamer>>>,
    pub subtitle_streamer: Option<Arc<Mutex<SubtitleStreamer>>>,
    pub player_state: Shared<PlayerState>,
    pub framerate: f64,
    pub texture_handle: TextureHandle,
    pub size: Vec2,
    pub looping: bool,
    pub audio_volume: Shared<f32>,
    pub max_audio_volume: f32,
    pub duration_ms: i64,
    /* private fields */
}
Expand description

The Player processes and controls streams of video/audio. This is what you use to show a video file. Initialize once, and use the Player::ui or Player::ui_at() functions to show the playback.

Fields§

§video_streamer: Arc<Mutex<VideoStreamer>>

The video streamer of the player.

§audio_streamer: Option<Arc<Mutex<AudioStreamer>>>

The audio streamer of the player. Won’t exist unless Player::with_audio is called and there exists a valid audio stream in the file.

§subtitle_streamer: Option<Arc<Mutex<SubtitleStreamer>>>

The subtitle streamer of the player. Won’t exist unless Player::with_subtitles is called and there exists a valid subtitle stream in the file.

§player_state: Shared<PlayerState>

The state of the player.

§framerate: f64

The framerate of the video stream.

§texture_handle: TextureHandle

The player’s texture handle.

§size: Vec2

The size of the video stream.

§looping: bool

Should the stream loop if it finishes?

§audio_volume: Shared<f32>

The volume of the audio stream.

§max_audio_volume: f32

The maximum volume of the audio stream.

§duration_ms: i64

The total duration of the stream, in milliseconds.

Implementations§

source§

impl Player

source

pub fn duration_text(&mut self) -> String

A formatted string for displaying the duration of the video stream.

source

pub fn elapsed_ms(&self) -> i64

The elapsed duration of the stream, in milliseconds. This value will won’t be truly accurate to the decoders while seeking, and will instead be overridden with the target seek location (for visual representation purposes).

source

pub fn pause(&mut self)

Pause the stream.

source

pub fn resume(&mut self)

Resume the stream from a paused state.

source

pub fn stop(&mut self)

Stop the stream.

source

pub fn stop_direct(&mut self)

Directly stop the stream. Use if you need to immmediately end the streams, and/or you aren’t able to call the player’s Player::ui/Player::ui_at functions later on.

source

pub fn seek(&mut self, seek_frac: f32)

Seek to a location in the stream.

source

pub fn start(&mut self)

Start the stream.

source

pub fn process_state(&mut self)

Process player state updates. This function must be called for proper function of the player. This function is already included in Player::ui or Player::ui_at.

source

pub fn generate_frame_image(&self, size: Vec2) -> Image<'_>

Create the egui::Image for the video frame.

source

pub fn render_frame(&self, ui: &mut Ui, size: Vec2) -> Response

Draw the video frame with a specific rect (without controls). Make sure to call Player::process_state.

source

pub fn render_frame_at(&self, ui: &mut Ui, rect: Rect) -> Response

Draw the video frame (without controls). Make sure to call Player::process_state.

source

pub fn ui(&mut self, ui: &mut Ui, size: Vec2) -> Response

Draw the video frame and player controls and process state changes.

source

pub fn ui_at(&mut self, ui: &mut Ui, rect: Rect) -> Response

Draw the video frame and player controls with a specific rect, and process state changes.

source

pub fn render_subtitles(&mut self, ui: &mut Ui, frame_response: &Response)

Draw the subtitles, if any. Only works when a subtitle streamer has been already created with Player::add_subtitles or Player::with_subtitles and a valid subtitle stream exists.

source

pub fn render_controls(&mut self, ui: &mut Ui, frame_response: &Response)

Draw the player controls. Make sure to call Player::process_state(). Unless you are explicitly drawing something in between the video frames and controls, it is probably better to use Player::ui or Player::ui_at.

source

pub fn add_audio(&mut self, audio_device: &mut AudioDevice) -> Result<()>

Initializes the audio stream (if there is one), required for making a Player output audio. Will stop and reset the player’s state.

source

pub fn add_subtitles(&mut self) -> Result<()>

Initializes the subtitle stream (if there is one), required for making a Player display subtitles. Will stop and reset the player’s state.

source

pub fn cycle_subtitle_stream(&mut self)

Switches to the next subtitle stream.

source

pub fn cycle_audio_stream(&mut self)

Switches to the next audio stream.

source

pub fn with_audio(self, audio_device: &mut AudioDevice) -> Result<Self>

Enables using Player::add_audio with the builder pattern.

source

pub fn with_subtitles(self) -> Result<Self>

Enables using Player::add_subtitles with the builder pattern.

source

pub fn new(ctx: &Context, input_path: &String) -> Result<Self>

Create a new Player.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Player

§

impl Send for Player

§

impl !Sync for Player

§

impl Unpin for Player

§

impl !UnwindSafe for Player

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.