/ / Come posso riprodurre un video e mettere in pausa in jQuery? - javascript, jquery, wordpress, dom, video

Come posso riprodurre un video e metterlo in pausa in jQuery? - javascript, jquery, wordpress, dom, video

Ciao, sto lavorando su un sito Web wordpress usandocompositore visivo. In una sezione di pagina ho un video di sfondo che vorrei mettere in pausa e giocare con un pulsante. Ora ho il pulsante in basso a destra sullo schermo e sono in grado di mettere in pausa il video, ma ho difficoltà a trovare il codice per riprodurlo di nuovo. Fondamentalmente vorrei il pulsante per alternare il video da uno stato di riproduzione / pausa. Questo è il mio codice attuale e mi sono perso su come procedere.

jQuery( document ).ready(function() {

jQuery(".sound-toggle").click( function (){

/* pause the video in the page section */
jQuery(".mk-section-video video").get(0).pause();

/* change button icon when toggled */
jQuery(this).toggleClass("mk-moon-volume-2 mk-moon-volume-mute-2");
});

}};

risposte:

0 per risposta № 1
jQuery( document ).ready(function() {

jQuery(".sound-toggle").click( function (){

if(jQuery(".mk-section-video video").paused){


/* pause the video in the page section */
jQuery(".mk-section-video video").get(0).pause();

/* change button icon when toggled */
jQuery(this).toggleClass("mk-moon-volume-2 mk-moon-volume-mute-2");

}else{

/* play the video in the page section */
jQuery(".mk-section-video video").get(0).play();

/* change button icon when toggled */
jQuery(this).toggleClass("mk-moon-volume-2 mk-moon-volume-mute-2");

}

});

}};

0 per risposta № 2

Secondo Questo, playun video in JavaScript è uguale a pause, così :

$(document).ready(function() {
//........

bindPlayVideo();
}):

function bindPlayVideo() {
$("#yourButtonId").click(function() {
var videoEl = $(".mk-section-video video").get(0);
videoEl.play();
});