Create event listeners once in Streamer class

This commit is contained in:
Christer Warén 2023-06-08 00:30:01 +03:00
parent 408c5aaab8
commit 2579549f0b

View File

@ -64,6 +64,23 @@ export default class Streamer {
}); });
} }
audioPlayer
.on(AudioPlayerStatus.Playing, () => {
logger('Streamer', station.name + " / " + "Playing");
})
.on(AudioPlayerStatus.Idle, () => {
logger('Streamer', station.name + " / " + "Idle");
})
.on(AudioPlayerStatus.Paused, () => {
logger('Streamer', station.name + " / " + "Paused");
})
.on(AudioPlayerStatus.Buffering, () => {
logger('Streamer', station.name + " / " + "Buffering");
})
.on(AudioPlayerStatus.AutoPaused, () => {
logger('Streamer', station.name + " / " + "AutoPaused");
})
this.map.set(station.name, audioPlayer); this.map.set(station.name, audioPlayer);
} }
@ -71,22 +88,6 @@ export default class Streamer {
const resource = createAudioResource(url); const resource = createAudioResource(url);
audioPlayer.play(resource); audioPlayer.play(resource);
audioPlayer
.on(AudioPlayerStatus.Playing, () => {
logger('Streamer', station.name + " / " + "Playing");
})
.on(AudioPlayerStatus.Idle, () => {
logger('Streamer', station.name + " / " + "Idle");
})
.on(AudioPlayerStatus.Paused, () => {
logger('Streamer', station.name + " / " + "Paused");
})
.on(AudioPlayerStatus.Buffering, () => {
logger('Streamer', station.name + " / " + "Buffering");
})
.on(AudioPlayerStatus.AutoPaused, () => {
logger('Streamer', station.name + " / " + "AutoPaused");
})
return audioPlayer; return audioPlayer;
} }