Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🚀esl-media]: ESLMediaManger implementation to handle all play/pause behavior + preconditions #2897

Open
ala-n opened this issue Jan 29, 2025 · 0 comments
Assignees

Comments

@ala-n
Copy link
Collaborator

ala-n commented Jan 29, 2025

It is proposed to rework the ESLMedia flow to resolve the following points:

User cases:

Autoplay

  • If the video (on the page) is marked as autoplay, then

    • if marked play-in-vieport -> start if is visible (in viewport)
    • if not marked play-in-vieport -> always start
  • If video is inside container

    • video was not played

      • if marked play-in-vieport -> start if is visible (in viewport)
      • if not marked play-in-vieport -> always start
    • video was played (container was opened previously)

      • if marked play-in-vieport -> start if is visible (in viewport)
      • if not marked play-in-vieport -> always start

    Note:
    Edge case - user decides to deprecate autostart in container second time

    ESLMediaManager.addRestriction( ($media) => !$media.played && isInContainer($media) )
    

Container

  • if the container is closed -> video inside should be paused automatically

User behavior

  • if video was stopped/paused by user behavior (click or direct call of pause/stop) -> video can not be started automatically (e.g. play-in-viewport, autoplay, etc)

Restriction API

Original proposal

// Declare before registration to cover autoplay 
const restriction = ($media: ESLMedia) => {
    return $media.type = 'video' && matchMedia('(user-prefer-no-motion)').matching;
};
ESLMediaRestrictionManager.add(restiction); // To add restriction hook
ESLMediaRestrictionManager.delete(restiction); // To remove if required
//
ESLMedia.register();

Alternative (EventAPI)

window.addEventListener('esl:media:before:play', (event: Event) => {
   // 1. The event is Cancelable
   // 2 The event contain all required inforamtion
   if (e.target.type === 'video' && matchMedia('(user-prefer-no-motion)').matching) {
      e.prventDefault(); // Reject playing the video
   }
});

ESLMedia.register();

Tech details

TODO @ala-n

@ala-n ala-n added the waits triage Issue that waits to be reviewed and handled label Jan 29, 2025
@ala-n ala-n removed the waits triage Issue that waits to be reviewed and handled label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants