Answer the question
In order to leave comments, you need to log in
How to use a function within a function within a class?
Good afternoon!
There is a service in angular (to listen to music).
there he is:
export class PlayService {
private audios = [];
private nowPlaying = 0;
private player = new Audio();
public addAudios(data, nowPlaying){
this.audios = [];
this.audios = data;
this.nowPlaying = nowPlaying;
console.log('End sending');
console.log('Start audio file');
this.player.src = 'src/files/'+this.audios[nowPlaying]['file'];
this.player.play();
this.player.addEventListener('ended', function (){
this.nextSong(); // вот здесь ругается
console.log('Audio file ended');
});
}
public nextSong(){
console.log('Start next audio file');
this.nowPlaying++;
this.player.src = 'src/files/'+this.audios[this.nowPlaying]['file'];
this.player.play();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question