This commit is contained in:
Peter Maquiran
2023-12-13 18:19:08 +01:00
parent 56c5416aac
commit e2cf79352e
8 changed files with 71 additions and 19 deletions
@@ -24,7 +24,7 @@ export class VisibilityDirective {
entries.forEach(entry => {
if (entry.isIntersecting) {
this.appVisibility(true);
// this.stopvideoService.registerVideo(this.elementRef.nativeElement)
this.stopvideoService.registerVideo(this.elementRef.nativeElement)
} else {
this.elementRef.nativeElement.pause()
// Pause video when not visible
+12
View File
@@ -15,6 +15,13 @@ export class StopvideoService {
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && !event.url.includes('/home/publications')) {
this.stopAndRemoveAllVideos();
// Get all video elements in the document
var videoElements = document.querySelectorAll('video');
// Pause each video element
videoElements.forEach(function(video) {
video.pause();
});
}
});
@@ -25,6 +32,11 @@ export class StopvideoService {
this.video.push(tagVideo);
}
registerVideoWithEvent(event: any) {
const videoElement: HTMLVideoElement = event.target as HTMLVideoElement;
this.video.push(videoElement);
}
stopAndRemoveAllVideos() {
for (let i = 0; i < this.video.length; i++) {
const video = this.video[i];