GPUI Box GitHub

Components / media

VideoPlayer builder

A player for one piece of video.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::media::VideoPlayer;

Reviewed in video-player.

Construct
new(ident: impl Into<Ident>) -> Self
Options

Chain onto the value.

title(title: impl Into<SharedString>) -> Self
transport(transport: Rc<dyn MediaTransport>) -> Self
frame(supplier: impl Fn(&mut Window, &mut App) -> Option<AnyElement> + 'static) -> Self
poster(supplier: impl Fn(&mut Window, &mut App) -> Option<AnyElement> + 'static) -> Self
ratio(ratio: f32) -> Self
ratio_of(width: f32, height: f32) -> Self
elapsed(elapsed: impl Into<SharedString>) -> Self
remaining(remaining: impl Into<SharedString>) -> Self
step_seconds(seconds: f32) -> Self
speeds(speeds: impl IntoIterator<Item = f32>) -> Self
presentation(state: MediaPresentation, label: impl Into<SharedString>) -> Self
presentation_refused(reason: impl Into<SharedString>) -> Self
on_presentation_request(handler: impl Fn(MediaPresentation, &mut Window, &mut App) + 'static) -> Self
on_event(handler: impl Fn(&MediaEvent, &mut Window, &mut App) + 'static) -> Self
Example · video-player
fn video_player(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(392.0))
        .child(
            VideoPlayer::new("scene.video.frame")
                .control_size(gpui_kit_theme::ControlSize::Touch)
                .presentation(
                    crate::content::transport::MediaPresentation::Inline,
                    "Present video",
                )
                .presentation_refused("Fixture host: native video presentation is unavailable.")
                .on_presentation_request(|_, _, _| {})
                .title("Screen capture")
                .transport(
                    FixtureTransport::ready(96.0)
                        .position(24.0)
                        .state(TransportState::Playing)
                        .volume(0.6)
                        .shared(),
                )
                .frame(|_, cx| Some(walkthrough_frame(cx)))
                .elapsed("00:24")
                .remaining("-01:12")
                .on_event(|_, _, _| {}),
        )
        .child(
            Divider::new()
                .id("scene.video.rule.poster")
                .label("Poster while the first frame is still unavailable"),
        )
        .child(
            VideoPlayer::new("scene.video.poster")
                .title("Release walkthrough")
                .transport(FixtureTransport::ready(240.0).shared())
                .poster(|_, cx| Some(walkthrough_poster(cx)))
                .elapsed("00:00")
                .remaining("-04:00")
                .on_event(|_, _, _| {}),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/media/video_player.rs