forked from Jibo-Revival-Group/JiboOs
Version 3.1 InDev
This commit is contained in:
61
V3.1/build/opt/jibo/Jibo/Skills/jibo-tbd/LocalRadioPlayer.js
Normal file
61
V3.1/build/opt/jibo/Jibo/Skills/jibo-tbd/LocalRadioPlayer.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const EventEmitter = require('events');
|
||||
|
||||
class LocalRadioPlayer extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this._stations = {
|
||||
'Rock': 'http://localhost:8000/rock',
|
||||
'Pop': 'http://localhost:8000/pop',
|
||||
'Jazz': 'http://localhost:8000/jazz',
|
||||
'Classical': 'http://localhost:8000/classical',
|
||||
'Electronic': 'http://localhost:8000/electronic',
|
||||
'Hip-Hop': 'http://localhost:8000/hiphop'
|
||||
};
|
||||
this._audio = null;
|
||||
}
|
||||
|
||||
getStations(options) {
|
||||
return Promise.resolve(Object.keys(this._stations).map(genre => ({
|
||||
name: genre,
|
||||
id: genre
|
||||
})));
|
||||
}
|
||||
|
||||
play(stationData) {
|
||||
if (this._audio) {
|
||||
this._audio.pause();
|
||||
}
|
||||
const streamUrl = this._stations[stationData.id];
|
||||
if (!streamUrl) {
|
||||
this.emit('error', new Error(`Station ${stationData.id} not found.`));
|
||||
return;
|
||||
}
|
||||
|
||||
this._audio = new Audio(streamUrl);
|
||||
this._audio.play()
|
||||
.then(() => {
|
||||
this.emit('song-data', {
|
||||
title: `Streaming ${stationData.id}`,
|
||||
artist: 'Local Radio',
|
||||
albumArt: ''
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
this.emit('error', err);
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this._audio) {
|
||||
this._audio.pause();
|
||||
this._audio = null;
|
||||
}
|
||||
}
|
||||
|
||||
resizeArtwork(options) {
|
||||
// Not applicable for local streaming without metadata
|
||||
return Promise.resolve('');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LocalRadioPlayer;
|
||||
@@ -1,2 +1,11 @@
|
||||
let thisPackage = require('./package.json');
|
||||
module.exports = thisPackage.version;
|
||||
const LocalRadioPlayer = require('./LocalRadioPlayer');
|
||||
|
||||
/**
|
||||
* @returns {RadioPlayer}
|
||||
*
|
||||
* i tried to make the radio work as well, coldnt get it to work :(
|
||||
*/
|
||||
module.exports = function createRadio() {
|
||||
return new LocalRadioPlayer();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user