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
impl Player
sourcepub fn duration_text(&mut self) -> String
pub fn duration_text(&mut self) -> String
A formatted string for displaying the duration of the video stream.
sourcepub fn elapsed_ms(&self) -> i64
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).
sourcepub fn stop_direct(&mut self)
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.
sourcepub fn process_state(&mut self)
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
.
sourcepub fn generate_frame_image(&self, size: Vec2) -> Image<'_>
pub fn generate_frame_image(&self, size: Vec2) -> Image<'_>
Create the egui::Image
for the video frame.
sourcepub fn render_frame(&self, ui: &mut Ui, size: Vec2) -> Response
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
.
sourcepub fn render_frame_at(&self, ui: &mut Ui, rect: Rect) -> Response
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
.
sourcepub fn ui(&mut self, ui: &mut Ui, size: Vec2) -> Response
pub fn ui(&mut self, ui: &mut Ui, size: Vec2) -> Response
Draw the video frame and player controls and process state changes.
sourcepub fn ui_at(&mut self, ui: &mut Ui, rect: Rect) -> Response
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.
sourcepub fn render_subtitles(&mut self, ui: &mut Ui, frame_response: &Response)
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.
sourcepub fn render_controls(&mut self, ui: &mut Ui, frame_response: &Response)
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
.
sourcepub fn add_audio(&mut self, audio_device: &mut AudioDevice) -> Result<()>
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.
sourcepub fn add_subtitles(&mut self) -> Result<()>
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.
sourcepub fn cycle_subtitle_stream(&mut self)
pub fn cycle_subtitle_stream(&mut self)
Switches to the next subtitle stream.
sourcepub fn cycle_audio_stream(&mut self)
pub fn cycle_audio_stream(&mut self)
Switches to the next audio stream.
sourcepub fn with_audio(self, audio_device: &mut AudioDevice) -> Result<Self>
pub fn with_audio(self, audio_device: &mut AudioDevice) -> Result<Self>
Enables using Player::add_audio
with the builder pattern.
sourcepub fn with_subtitles(self) -> Result<Self>
pub fn with_subtitles(self) -> Result<Self>
Enables using Player::add_subtitles
with the builder pattern.