Update Streamer class

This commit is contained in:
Christer Warén 2021-11-16 16:55:47 +02:00
parent 93a4f3e0c4
commit d67fa68445

View File

@ -49,12 +49,22 @@ module.exports = class {
play(station) {
let audioPlayer = this.map.get(station.name);
if(!audioPlayer) {
audioPlayer = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});
if(this.mode == "auto"){
audioPlayer = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});
}
if(this.mode == "manual"){
audioPlayer = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Stop,
maxMissedFrames: Math.round(5000 / 20),
},
});
}
this.map.set(station.name, audioPlayer);
}
const url = station.stream[station.stream.default];
@ -77,22 +87,18 @@ module.exports = class {
})
.on('idle', () => {
this.logger('Streamer', station.name + " / " + "Idle");
this.play(station);
})
.on('paused', () => {
this.logger('Streamer', station.name + " / " + "Paused");
this.play(station);
})
.on('buffering', () => {
this.logger('Streamer', station.name + " / " + "Buffering");
})
.on('autopaused', () => {
this.logger('Streamer', station.name + " / " + "AutoPaused");
this.play(station);
})
.on('error', error => {
this.logger('Streamer', station.name + " / " + "Error" + "\n" + error);
this.play(station);
});
return audioPlayer;
}