Components / media
AudioWaveform builder
A measured waveform the host already sampled.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::media::AudioWaveform;
Reviewed in audio-waveform.
Construct
new(ident: impl Into<Ident>) -> Self
Options
Chain onto the value.
peaks(peaks: impl IntoIterator<Item = f32>) -> Self
playhead(fraction: f32) -> Self
state(state: AudioWaveformState) -> Self
Example · audio-waveform
fn audio_waveform(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
stack(&theme)
.w(px(520.0))
.child(caption(
&theme,
"already-normalized peaks; a missing playhead draws no played split",
))
.child(
AudioWaveform::new("scene.waveform.ready")
.peaks(scene_peaks(48))
.playhead(0.38),
)
.child(AudioWaveform::new("scene.waveform.loading").state(AudioWaveformState::Loading))
.child(AudioWaveform::new("scene.waveform.empty").state(AudioWaveformState::Empty))
.child(AudioWaveform::new("scene.waveform.unavailable").state(
AudioWaveformState::Unavailable("The sampler host refused the request.".into()),
))
.child(
AudioWaveform::new("scene.waveform.error").state(AudioWaveformState::Error(
"The sampler request failed.".into(),
)),
)
.into_any_element()
}