HTML Audio/Video DOM pause() Method The pause() method halts (pauses) the currently playing audio or video.
You can use Javascript to perform such actions. var myAudio = document. getElementById("myAudio"); var isPlaying = false; function togglePlay() { if (isPlaying) { myAudio. pause() } else { myAudio.
onplay = function() { vid2. pause(); };
HTML | DOM Audio pause() Method The HTML DOM Audio pause() Method is used to pause the currently playing audio. To use the audio pause() method, one must use the controls property to display the audio controls such as play, pause, volume, etc, attached on the audio.
Your solution shows the issue here -- play
is not a jQuery function but a function of the DOM element. You therefore need to call it upon the DOM element. You give an example of how to do this with the native DOM functions. The jQuery equivalent -- if you wanted to do this to fit in with an existing jQuery selection -- would be $('#videoId').get(0).play()
. (get
gets the native DOM element from the jQuery selection.)
You can do
$('video').trigger('play');
$('video').trigger('pause');
This is how I managed to make it work:
jQuery( document ).ready(function($) {
$('.myHTMLvideo').click(function() {
this.paused ? this.play() : this.pause();
});
});
All my HTML5 tags have the class 'myHTMLvideo'
Why do you need to use jQuery? Your proposed solution works, and it's probably faster than constructing a jQuery object.
document.getElementById('videoId').play();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With