pub struct MediaEvent {
pub kind: MediaEventKind,
pub current_time: f64,
pub duration: Option<f64>,
pub paused: bool,
pub ended: bool,
pub muted: bool,
pub volume: f64,
pub buffered: f64,
}Expand description
Structure passed as a parameter to callback on on_media event: what happened to
a <video> or an <audio>, and its state right after.
Every event comes with the whole state, so a player can keep it in one value and draw its
controls from it. It changes the media through the element’s DomElementRef:
use vertigo::{MediaEvent, Value, bind, dom, dom_element, transaction};
let playing = Value::new(false);
let video = dom_element! {
<video src="/film.mp4" preload="metadata" on_media={bind!(playing, |event: MediaEvent| {
playing.set(!event.paused);
})} />
};
let video_ref = video.get_ref();
let toggle = bind!(playing, video_ref, |_| {
let method = if transaction(|ctx| playing.get(ctx)) { "pause" } else { "play" };
video_ref.dom_access().call(method, vec![]).fetch();
});
let label = playing.map(|playing| if playing { "Pause" } else { "Play" });
dom! {
<div>
{video}
<button on_click={toggle}>{label}</button>
</div>
};Fields§
§kind: MediaEventKind§current_time: f64The position, in seconds.
duration: Option<f64>The length, in seconds. None until the metadata comes, and for a stream with no end.
paused: bool§ended: bool§muted: bool§volume: f64From 0 to 1.
buffered: f64Up to where it’s in the browser from the current position on, in seconds - what plays without waiting for the network. The current position, when nothing ahead is there.
Trait Implementations§
Source§impl Clone for MediaEvent
impl Clone for MediaEvent
Source§impl Debug for MediaEvent
impl Debug for MediaEvent
Source§impl Display for MediaEvent
impl Display for MediaEvent
Source§impl PartialEq for MediaEvent
impl PartialEq for MediaEvent
impl StructuralPartialEq for MediaEvent
Auto Trait Implementations§
impl Freeze for MediaEvent
impl RefUnwindSafe for MediaEvent
impl Send for MediaEvent
impl Sync for MediaEvent
impl Unpin for MediaEvent
impl UnsafeUnpin for MediaEvent
impl UnwindSafe for MediaEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more