secuencia de comandos de video de detención de jQuery

This script work perfectly, but what it does is stops an instance of a playing video if a new video is started. How would I rewrite this to stop ALL instances of playing videos when the function stopAllButMe(); ¿se llama?

function stopAllButMe(playerState, player) {
    if (playerState=='PLAYING') {
        var myId = player.getId();
        projekktor('*').each(function() {
            if (this.getId()!==myId) {
                this.setStop();
            }
        });
    }
}

projekktor('*').each(function() {
    this.addListener('state', stopAllButMe);
});

preguntado el 01 de febrero de 12 a las 22:02

2 Respuestas

function stopAllButMe(playerState) {
  if (playerState=='PLAYING') {
    projekktor('*').each(function() {

      this.setStop();

    });
  }
}
projekktor('*').each(function() {
  this.addListener('state', stopAllButMe);
});

The 'if' statement was checking against the input.

Respondido 02 Feb 12, 02:02

this kind of works...except you cant even click play on the video because the script automatically immediately stops it. - Blainer

is there a way to have this script run only when its called? - Blainer

function stopAllButMe (state, player) {

    //iterate through each of the `<video>` elements
    $.each($('video'), function () {

        //check if the current iteration is the same element that got passed into this function
        if (this.id != player.id) {

            //stop any `<video>` element that isn't the one passed into this function
            this.stop();
        }
    });
}

//find each `<video>` element and add an event handler for the `state` event
$('video').bind('state', stopAllButMe);

This assumes that each <video> tag has it's own unique ID.

Respondido 02 Feb 12, 02:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.