Skip to content

Commit

Permalink
feat(video-player): allow opt out autoplay pref set
Browse files Browse the repository at this point in the history
  • Loading branch information
m4olivei committed Dec 19, 2024
1 parent 72a37f8 commit a751947
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class C4DVideoPlayerComposite extends HybridRenderMixin(
if (entry.isIntersecting && this._getAutoplayPreference() !== false) {
this._embedMedia?.(videoId);
this.playAllVideos();
this._setAutoplayPreference(true);
}
});
}
Expand All @@ -155,7 +154,7 @@ class C4DVideoPlayerComposite extends HybridRenderMixin(
private _intersectionOutOfViewHandler(entries: IntersectionObserverEntry[]) {
entries.forEach((entry) => {
if (!entry.isIntersecting) {
this.pauseAllVideos();
this.pauseAllVideos(false);
}
});
}
Expand Down Expand Up @@ -211,25 +210,29 @@ class C4DVideoPlayerComposite extends HybridRenderMixin(
}
}

pauseAllVideos() {
pauseAllVideos(updateAutoplayPreference = true) {
const { embeddedVideos = {} } = this;

Object.keys(embeddedVideos).forEach((videoId) => {
embeddedVideos[videoId].sendNotification('doPause');
});
this.isPlaying = false;
this._setAutoplayPreference(false);
if (updateAutoplayPreference) {
this._setAutoplayPreference(false);
}
}

playAllVideos() {
playAllVideos(updateAutoplayPreference = true) {
const { embeddedVideos = {} } = this;

Object.keys(embeddedVideos).forEach((videoId) => {
embeddedVideos[videoId].sendNotification('doPlay');
});
this.isPlaying = true;
this.playbackTriggered = true;
this._setAutoplayPreference(true);
if (updateAutoplayPreference) {
this._setAutoplayPreference(true);
}
}

/**
Expand Down

0 comments on commit a751947

Please sign in to comment.