Reputation: 43
How to get curentTime from Html5 Audio.I did not place audio html tag . I just want to do it in typescript.i get TypeError: Cannot read property 'currentTime' of undefined. I think there is something wrong with current context ? how can i fix it with apply & bind or any other technique ?
//player.ts
audio = new Audio();
btnPlay(){
this.audio.src = "media/Audio_1.mp3";
this.audio.load();
this.audio.play();
this.audio.addEventListener('timeupdate',this.timeupdate)
}
timeupdate(e){
console.log(this.audio.currentTime);
}
Upvotes: 0
Views: 1411
Reputation: 1080
Make timeupdate
an arrow function:
timeupdate = (e) => {
console.log(this.audio.currentTime);
}
See https://www.typescriptlang.org/docs/handbook/functions.html#this-and-arrow-functions for more information.
Upvotes: 3