Skip to content

Commit

Permalink
chore(esl-media): remove interrupt attribute, replace with 'always' a…
Browse files Browse the repository at this point in the history
…utoplay
  • Loading branch information
fshovchko committed Dec 2, 2024
1 parent 48fd7ef commit eef78ba
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/modules/esl-media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ using a single tag as well as work with external providers using simple native-l

- `autofocus` (boolean) - set focus to the player when the media starts playing

- `autoplay` (boolean) - start to play automatically on initialization
- `autoplay` (boolean | 'always') - start to play automatically on initialization. When set to 'always', the video will auto play even if previously stopped by the user, otherwise, it will not.
*(note: initialization doesn't happen until `disabled` attribute is removed from the element)*

- `controls` (boolean) - show media player controls
Expand Down
2 changes: 1 addition & 1 deletion src/modules/esl-media/core/esl-media-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface MediaProviderConfig {
loop: boolean;
muted: boolean;
controls: boolean;
autoplay: boolean;
autoplay: boolean | 'always';
title: string;
preload?: 'none' | 'metadata' | 'auto' | '';
playsinline?: boolean;
Expand Down
14 changes: 7 additions & 7 deletions src/modules/esl-media/core/esl-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {SPACE, PAUSE} from '../../esl-utils/dom/keys';
import {prop, attr, boolAttr, listen} from '../../esl-utils/decorators';
import {debounce} from '../../esl-utils/async';
import {isVisible} from '../../esl-utils/dom/visible';
import {parseAspectRatio} from '../../esl-utils/misc/format';
import {parseAspectRatio, parseBoolean, parseString} from '../../esl-utils/misc/format';

import {ESLMediaQuery} from '../../esl-media-query/core';
import {ESLResizeObserverTarget} from '../../esl-event-listener/core';
Expand Down Expand Up @@ -81,9 +81,10 @@ export class ESLMedia extends ESLBaseElement {
/** Allows lazy load resource */
@attr({parser: parseLazyAttr, defaultValue: 'none'}) public lazy: ESLMediaLazyMode;
/** Autoplay resource marker */
@boolAttr() public autoplay: boolean;
/** Will prevent autoplay if media was paused manually */
@boolAttr() public noAutoplayOnInterrupt: boolean;
@attr({
defaultValue: false,
parser: (value: string) => value === 'always' ? parseString(value) : parseBoolean(value)
}) public autoplay: 'always' | boolean;
/** Autofocus on play marker */
@boolAttr() public override autofocus: boolean;
/** Mute resource marker */
Expand Down Expand Up @@ -197,8 +198,7 @@ export class ESLMedia extends ESLBaseElement {
}

public canAutoplay(): boolean {
if (!this.autoplay) return false;
return !(this.noAutoplayOnInterrupt && !this.autopaused);
return !!this.autoplay && (this.autoplay === 'always' || this.autopaused);
}

private reinitInstance(): void {
Expand Down Expand Up @@ -353,7 +353,7 @@ export class ESLMedia extends ESLBaseElement {
protected _onContainerShow(e: Event): void {
const {target} = e;
if (!isSafeContains(target as Node, this)) return;
if (this.playInViewport && isVisible(this)) return;
if (this.playInViewport && !isVisible(this)) return;
if (this.canAutoplay()) this.play();
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/esl-media/providers/brightcove-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class BrightcoveProvider extends BaseProvider {
*/
protected onAPIReady(): Promise<void> | void {
// Set autoplay though js because BC is unresponsive while processing it natively
this._api.autoplay(this._autoplay || this.config.autoplay);
this._api.autoplay(this._autoplay || !!this.config.autoplay);

// Listeners to control player state
this._api.on('play', () => this.component._onPlay());
Expand Down
2 changes: 1 addition & 1 deletion src/modules/esl-media/providers/html5/media-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export abstract class HTMLMediaProvider extends BaseProvider {

protected static applyElementSettings(el: HTMLMediaElement, cfg: MediaProviderConfig): HTMLMediaElement {
el.classList.add('esl-media-inner');
el.autoplay = cfg.autoplay;
el.autoplay = !!cfg.autoplay;
el.preload = cfg.preload || 'auto' ;
el.loop = cfg.loop;
el.muted = cfg.muted;
Expand Down

0 comments on commit eef78ba

Please sign in to comment.