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('sending End');
console.log('Start of audio file');
this.player.src = 'src/files/'+this.audios[nowPlaying]['file'];
this.player.play();
this.player.addEventListener('ended', function (){
this.nextSong(); // swears here
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();
}
}
this.player.addEventListener('ended', () => {
this.nextSong();
console.log('Audio file ended');
});
var self = this;
this.player.addEventListener('ended', function (){
self.nextSong();
console.log('Audio file ended');
});
this.player.addEventListener('ended', () => {
this.nextSong();
console.log('Audio file ended');
});
Find more questions by tags AngularJavaScript