I have implemented Visibility API inside a constructor of an Angular component similar to this
constructor() {
var hidden, state, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
state = "visibilityState";
}
document.addEventListener(visibilityChange, function() {
if(status == hidden){
console.log("Hidden");
}
else if(status != hidden){
console.log("Visible");
}
}, false);
}
pauseVideo(){
//Video pause code
}
I need to pause the video i.e., call the pauseVideo() method when the Visibility changes to hidden, How do i do it?
if (document.hidden) {to see if the document is visible or not.if (document.hidden)but the method can't be accessed inside the document event listener, i googled some more and an answer was to use a service to broadcast an event when this happens; Any idea about it?