So I have embedded a vimeo video in my Angular 8 app and am now trying to trigger some animation after the video starts playing and once its ended. Essentially if screen width is <800
, the variable isMobile
is true
. Next I have the vimeo play
method being called which checks if isMobile
is true
, and sets load_completed
(which is the animation trigger) to true
. The isssue is that my variable isMobile
returns undefined
, why is that?
isMobile = false;
constructor() { }
ngOnInit() {
this.innerWidth = window.innerWidth;
console.log(this.innerWidth);
if (this.innerWidth < 800) {
this.isMobile = true;
}
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.on('play', function() {
//isMobile returns undefined why?
console.log(this.isMobile);
if (this.isMobile) {
this.load_completed = true;
}
console.log('Played the video');
});
player.on('ended', function(data) {
console.log('Video ended');
});
}