2017-04-09 16:30:20 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-04-09 20:57:32 +00:00
|
|
|
const throttle = require('throttle-debounce/throttle');
|
|
|
|
|
2017-04-09 16:30:20 +00:00
|
|
|
const ChildProcessEmitter = require('./child-process').ChildProcessEmitter;
|
|
|
|
|
2017-04-09 20:57:32 +00:00
|
|
|
const DEFAULT_PAUSE_THROTTLE = 2000;
|
|
|
|
const DEFAULT_PLAY_THROTTLE = 5000;
|
|
|
|
|
2017-04-09 16:30:20 +00:00
|
|
|
class MediaPlayer extends ChildProcessEmitter {
|
2017-04-09 20:57:32 +00:00
|
|
|
constructor(config, logger) {
|
|
|
|
super(config.mpg321, logger);
|
|
|
|
|
|
|
|
this.stderrFilters.push(line => {
|
|
|
|
return line.substr(0, 3) == '@F '
|
|
|
|
});
|
|
|
|
|
|
|
|
this.pauseThrottled = throttle(config.pause_throttle || DEFAULT_PAUSE_THROTTLE, () => {
|
|
|
|
this._pause();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.playFileThrottled = throttle(config.play_throttle || DEFAULT_PLAY_THROTTLE, (path) => {
|
|
|
|
this._playFile(path);
|
|
|
|
});
|
|
|
|
|
|
|
|
// default to unthrottled
|
|
|
|
this.pause = this._pauseFile;
|
|
|
|
this.playFile = this._playFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
throttle() {
|
|
|
|
this.pause = this.pauseThrottled;
|
|
|
|
this.playFile = this.playFileThrottled;
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
this.send('STOP');
|
|
|
|
}
|
|
|
|
|
|
|
|
_pause() {
|
|
|
|
this.send('PAUSE');
|
|
|
|
}
|
|
|
|
|
|
|
|
_playFile(path) {
|
|
|
|
this.send("LOAD " + path);
|
|
|
|
}
|
2017-04-09 16:30:20 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 17:55:11 +00:00
|
|
|
module.exports = function(config, logger) {
|
2017-04-09 20:57:32 +00:00
|
|
|
return new MediaPlayer(config, logger);
|
2017-04-09 16:30:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:set ts=2 sw=2 et:
|