Is there a way to change the custom icon of a video when it is toggled between Play and Pause?
ngAfterViewInit() {
const vdoCont = document.querySelector('.video-player');
const vdo = vdoCont.querySelector('video');
vdo.addEventListener('play', () => {
console.log(this) // This "this" refers to the TypeScript class
this.updateVdoIcon(this);
});
vdo.addEventListener('pause', () => {
console.log(this) // Here "this" refers to typescript class
this.updateVdoIcon(this);
});
}
updateVdoIcon(videoElment: any) {
console.log(videoElment); // I'm expecting this to be the video element instead of the TypeScript class
}
I attempted to change arrow functions to JavaScript functions, but then I can't utilize my "updateVdoIcon" function.
vdo.addEventListener('play', function() {
this.updateVdoIcon(this); // Property 'updateVdoIcon' does not exist on type 'HTMLVideoElement'
});
While I know I could use an anonymous function (as shown below) and update the icon there, what if I have a lot of code that I want to separate into a function?
vdo.addEventListener('play', function() {
this.paused ? console.log('Play icon') : console.log('Pause icon')
});