Skip to main content

MediaEvent

Struct MediaEvent 

Source
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: f64

The 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: f64

From 0 to 1.

§buffered: f64

Up 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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MediaEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MediaEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MediaEvent

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MediaEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.