web_sys::HtmlMediaElement::pause method

Example

This example demonstrates the use of the pause method of HTMLMediaElement Struct. The example starts by creating a button and associatit with a mouse click event. When the button is clicked, the video element is retrieved using the get_element_by_id method. The synchronous pause method is then called to pause the video.


pub fn web_sys_htmlmediaelement_pause(){
    let window = web_sys::window().expect("global window does not exists");    
    let document = window.document().expect("expecting a document on window");
    let body = document.body().expect("document expect to have have a body");
    let button = document.create_element("button")
                    .unwrap()
                    .dyn_into::<web_sys::HtmlButtonElement>()
                    .unwrap();
    button.set_text_content(Some("Pause"));

    let paragraph = document.get_element_by_id("message")
                    .unwrap()
                    .dyn_into::<web_sys::HtmlParagraphElement>()
                    .unwrap();

    let on_click = EventListener::new(&button, "click", move |_event| {
        let _video = document.get_element_by_id("my-video")
        .unwrap()
        .dyn_into::<web_sys::HtmlMediaElement>()
        .unwrap();
    
        let _result=_video.pause();
        
        paragraph.set_text_content(Some("Pausing..."));
    
    });

    on_click.forget();     
    body.append_child(&button).unwrap();
}    

Method


    pub fn pause(&self) -> Result<(), JsValue>

features/dependencies

Source Code