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