2023-12-13 16:44:29 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { NavigationEnd, Router } from '@angular/router';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class StopvideoService {
|
|
|
|
|
|
|
|
|
|
video: HTMLVideoElement[] = []
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private router: Router
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
this.router.events.forEach((event) => {
|
|
|
|
|
if (event instanceof NavigationEnd && !event.url.includes('/home/publications')) {
|
|
|
|
|
this.stopAndRemoveAllVideos();
|
2023-12-13 18:19:08 +01:00
|
|
|
// Get all video elements in the document
|
|
|
|
|
var videoElements = document.querySelectorAll('video');
|
|
|
|
|
|
|
|
|
|
// Pause each video element
|
|
|
|
|
videoElements.forEach(function(video) {
|
|
|
|
|
video.pause();
|
|
|
|
|
});
|
2023-12-13 16:44:29 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerVideo(tagVideo: HTMLVideoElement) {
|
|
|
|
|
this.video.push(tagVideo);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 18:19:08 +01:00
|
|
|
registerVideoWithEvent(event: any) {
|
|
|
|
|
const videoElement: HTMLVideoElement = event.target as HTMLVideoElement;
|
|
|
|
|
this.video.push(videoElement);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 16:44:29 +01:00
|
|
|
stopAndRemoveAllVideos() {
|
|
|
|
|
for (let i = 0; i < this.video.length; i++) {
|
|
|
|
|
const video = this.video[i];
|
|
|
|
|
|
|
|
|
|
// Pause the video
|
|
|
|
|
video.pause();
|
|
|
|
|
|
|
|
|
|
// Optionally, you can also reset the current time to start from the beginning
|
|
|
|
|
video.currentTime = 0;
|
|
|
|
|
|
|
|
|
|
// Remove the video from the array
|
|
|
|
|
this.video.splice(i, 1);
|
|
|
|
|
|
|
|
|
|
// Decrement the index to properly continue the loop
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|