polimediaupv / paella-core

Paella Player core library
Educational Community License v2.0
20 stars 15 forks source link

Paella.js's "loadKeypressHandler" SPACE-key-play impacts defaultShortcuts SPACE-key-togglePlayPause #304

Closed karendolan closed 1 year ago

karendolan commented 1 year ago

The "loadKeypressHandler" is impacting my custom plugin that contains a text input form that overlays the player.

I'm able to suppress the space key press can from other listeners, EXCEPT for "loadKeypressHandler" , which captures the first space bar press, regardless of propagation suppression. It captures it and plays the player. This is after the player has been played and paused by the regular space bard default keyboard controls.

The "loadKeypressHandler" only launches once. Which explains why the player start playing but cannot also be paused with the space bar (from the textarea form in the overlay).

Workaround: I will try removing that one-off "loadKeypressHandler" to see where it was needed. It doesn't seem to be needed from a Mac os x laptop, Chrome or Safari... maybe some other device requires it?

https://github.com/polimediaupv/paella-core/blob/main/src/js/Paella.js#L185-L198 https://github.com/polimediaupv/paella-core/blob/main/src/js/plugins/es.upv.paella.defaultShortcuts.js#L217-L222 https://github.com/polimediaupv/paella-core/blob/main/src/js/plugins/es.upv.paella.defaultShortcuts.js#L60-L68 I added comments to the commit https://github.com/polimediaupv/paella-core/commit/5f12fbc08b6c3a835ceb229111bf5c89e489b53e

karendolan commented 1 year ago

For a temporary workaround, I put this at the end of the PaellaOpencast.js "loadVideoManifest()"

    window.__paella_instances__.push({
      PaellaOpencastSpaceHolder: 'ref https://github.com/polimediaupv/paella-core/issues/304'
    });
karendolan commented 1 year ago

A clarification... the issue is that when play is started with a mouse "click", instead of a space bar, on the loaded player preview image, that one-off space-bar listener remains intact. It keeps listening for a space-bar key press. It is never removed until later when a space bar key is finally first clicked.

Therefore, it would make sense to remove that initial one-off space bar listener immediately after the video is first played. If it can be removed when the a click starts the player, then that listener will not conflict with the keyboard shortcuts space-bar listener.

karendolan commented 1 year ago

Therefore I'm doing this:

    // #DCE adding a dummy second instance to prevent the space bar forever listening issue
    window.__paella_instances__.push({
      PaellaOpencastSpaceHolder: 'ref https://github.com/polimediaupv/paella-core/issues/304'
    });
    // Add the space bar listener back on
    const loadKeypressHandler = async (evt) => {
      if (/space/i.test(evt.code)) {
        await player.play();
        window.removeEventListener('keypress', loadKeypressHandler, true);
      }
    };
    window.addEventListener('keypress', loadKeypressHandler, true);
    // Add an extra lister to remove it on a click
    window.addEventListener('click', async () => {
      window.removeEventListener('keypress', loadKeypressHandler, true);
    });
    // end #DCE "loadKeypressHandler" override
polimediaupv commented 1 year ago

Keyboard shortcuts are a type of plugin, and therefore are not loaded until the player has finished loading. For that reason the spacebar is intercepted as a special case. In any case, that event handler should be uninstalled once the player has loaded, so this you comment is probably a bug.

I'm going to look into it now, because the problem seems to be quite easy to solve.