GPUI Box GitHub

Components / media

AudioPlayer builder

A player for one piece of audio.

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

use gpui_kit::media::AudioPlayer;

Reviewed in audio-player.

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

Chain onto the value.

title(title: impl Into<SharedString>) -> Self
subtitle(subtitle: impl Into<SharedString>) -> Self
transport(transport: Rc<dyn MediaTransport>) -> Self
elapsed(elapsed: impl Into<SharedString>) -> Self
remaining(remaining: impl Into<SharedString>) -> Self
peaks(peaks: impl IntoIterator<Item = f32>) -> Self
step_seconds(seconds: f32) -> Self
speeds(speeds: impl IntoIterator<Item = f32>) -> Self
on_event(handler: impl Fn(&MediaEvent, &mut Window, &mut App) + 'static) -> Self
Example · audio-player
fn audio_player(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(392.0))
        .child(
            AudioPlayer::new("scene.audio.ready")
                .control_size(gpui_kit_theme::ControlSize::Touch)
                .title("Release walkthrough")
                .subtitle("Recorded 12 March")
                .transport(
                    FixtureTransport::ready(240.0)
                        .position(72.0)
                        .state(TransportState::Playing)
                        .volume(0.7)
                        .buffered([BufferedRange::new(0.0, 156.0)])
                        .shared(),
                )
                .elapsed("01:12")
                .remaining("-02:48")
                .peaks(scene_peaks(96))
                .speeds([1.0, 1.5, 2.0])
                .step_seconds(10.0)
                .on_event(|_, _, _| {}),
        )
        .child(
            Divider::new()
                .id("scene.audio.rule.backend")
                .label("Nothing here can decode it"),
        )
        .child(
            AudioPlayer::new("scene.audio.absent")
                .title("interview.opus")
                .transport(
                    FixtureTransport::new()
                        .no_backend("There is no Opus decoder on this machine.")
                        .shared(),
                )
                .on_event(|_, _, _| {}),
        )
        .child(
            Divider::new()
                .id("scene.audio.rule.none")
                .label("No player connected at all"),
        )
        .child(
            AudioPlayer::new("scene.audio.none")
                .title("Standup recording")
                .on_event(|_, _, _| {}),
        )
        .into_any_element()
}

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