-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
46 lines (42 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* node-mpg123
* Javascript mpg123 wrapper for Node.js
*
* @author Maciej Sopyło (killah)
* Copyright 2012 Maciej Sopyło @ KILLAHFORGE.
*
* MIT License
*/
var spawn = require('child_process').spawn,
events = require('events'),
util = require('util');
module.exports = function Sound(filename) {
events.EventEmitter.call(this);
this.filename = filename;
};
util.inherits(module.exports, events.EventEmitter);
module.exports.prototype.play = function () {
this.stopped = false;
this.process = spawn('mpg123', [ this.filename ]);
var self = this;
this.process.on('exit', function (code, sig) {
if (code !== null && sig === null) {
self.emit('complete');
}
});
};
module.exports.prototype.stop = function () {
this.stopped = true;
this.process.kill('SIGTERM');
this.emit('stop');
};
module.exports.prototype.pause = function () {
if (this.stopped) return;
this.process.kill('SIGSTOP');
this.emit('pause');
};
module.exports.prototype.resume = function () {
if (this.stopped) return this.play();
this.process.kill('SIGCONT');
this.emit('resume');
};