Pause mediaelement.js using jquery

11,153

Each element with a media player element has a player property defined. This is where all the methods reside. You can access it with either of the following methods:

$('video')[0].player.pause(); // Be sure the video element exists.

$('video').each(function(){this.player.pause()}) // Safe.
Share:
11,153
evolutionxbox
Author by

evolutionxbox

SOreadytohelp

Updated on June 05, 2022

Comments

  • evolutionxbox
    evolutionxbox about 2 years

    I have initialised the element using:

    $('video').mediaelementplayer();
    

    Now I would like to target that video and pause it when a link is pressed:

    $('.page_button').live('click', function() {
        $('video').pause();
    });
    

    Thanks.

  • Manu
    Manu almost 10 years
    Important note: this only works if you explicitly create the player object using the var player = new MediaElementPlayer(... method.
  • Manu
    Manu almost 10 years
    One important detail: for the play() and pause() methods to work, you need to create the player object explicitly by using the var player = new MediaElementPlayer() method, as described at mediaelementjs.com. If you do that, even a simple player.pause() will do the trick.