1

Im new to angular 2 and ionic 2 ,Im using audio tags for my project for which in using audio Object

audio: any = new Audio();

In this I'm able to use play(),pause(),currentTime,duration,src,..etc but, in the "ontimeupdate" property if I call the the audio Object

this.audio

it gives me undefined.I need the "ontimeupdate" method to get the audios "currentTime" This is my code.

export class PlayerPage implements OnInit { 
audio: any = new Audio();


 constructor(public navCtrl: NavController, public global: GlobalDataService) 
{}

ngOnInit() {
   //click fn. triggered on btn click
    this.playSong();       
}

 playSong() {
    this.audio.src = "MY AUDIO FILE SRC";
    this.audio.load();
    this.audio.play();
 }

 this.audio.ontimeupdate = function () {
 //gives 'this.audio' as undefined
   console.log(this.audio); 

  console.log(this.audio.currentTime)    
 }  
 }

It gives undefined only in the "ontimeupdate" function else where if console the "this.audio" it shows the result.

deep dalvi
  • 119
  • 1
  • 1
  • 17

0 Answers0