Skip to content

Commit

Permalink
add group states
Browse files Browse the repository at this point in the history
  • Loading branch information
stamat committed Feb 7, 2024
1 parent b57ff9f commit b5710d0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/lib/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export class VideoBackgroundGroup {
this.videoBackgroundFactoryInstance = videoBackgroundFactoryInstance;
this.stack = [];
this.map = new Map();
this.current = 0;
this.currentElement = null;
this.currentInstance = null;

this.playing = false;
this.muted = true;

for (let i = 0; i < this.elements.length; i++) {
const element = this.elements[i];
Expand Down Expand Up @@ -104,7 +110,12 @@ export class VideoBackgroundGroup {
if (this.stack[this.current] !== event.detail.element) return;
this.setVideoBackgroundFactoryInstance(event);
const videoBackground = event.detail;
if (videoBackground.currentState !== 'playing' && videoBackground.isIntersecting) videoBackground.softPlay();
if (videoBackground.params.muted) this.muted = true;
if (!videoBackground.isIntersecting) return;
if (!videoBackground.params.autoplay) return;
this.playing = true;
if (videoBackground.currentState === 'playing') return;
videoBackground.softPlay();
}

onVideoPause(event) {;
Expand Down Expand Up @@ -202,6 +213,7 @@ export class VideoBackgroundGroup {
instance.unmute();
}

this.muted = false;
this.dispatchEvent('video-background-group-umnute');
}

Expand All @@ -212,16 +224,19 @@ export class VideoBackgroundGroup {
instance.mute();
}

this.muted = true;
this.dispatchEvent('video-background-group-mute');
}

pause() {
this.currentInstance.pause();
this.playing = false;
this.dispatchEvent('video-background-group-previous');
}

play() {
this.currentInstance.play();
this.playing = true;
this.dispatchEvent('video-background-group-previous');
}

Expand Down
21 changes: 19 additions & 2 deletions youtube-background-experimental.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5710d0

Please sign in to comment.