-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (53 loc) · 1.41 KB
/
index.js
File metadata and controls
59 lines (53 loc) · 1.41 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* node-simple-mplayer
* Javascript simple mplayer wrapper for Node.js
*
* @author Jonathan Blanchet (@jblanchefr)
* Copyright 2012 Jonathan Blanchet @ Lab212.
*
* MIT License
*/
var spawn = require('child_process').spawn,
events = require('events'),
util = require('util');
module.exports = function Media(filename) {
events.EventEmitter.call(this);
this.filename = filename;
};
util.inherits(module.exports, events.EventEmitter);
module.exports.prototype.play = function (options) {
this.stopped = false;
var args = [this.filename];
for(var prop in options) {
if(options.hasOwnProperty(prop)){
args.unshift('-'+prop, options[prop] );
}
}
this.process = spawn('mplayer', args);
this.process.on('exit', function (code, sig) {
if (code !== null && sig === null) {
this.emit('complete');
}
}.bind(this));
};
module.exports.prototype.stop = function () {
this.stopped = true;
if(this.process){
this.process.kill('SIGTERM');
}
this.emit('stop');
};
module.exports.prototype.pause = function () {
if (this.stopped) return;
if(this.process){
this.process.kill('SIGSTOP');
}
this.emit('pause');
};
module.exports.prototype.resume = function () {
if (this.stopped) return this.play();
if(this.process){
this.process.kill('SIGCONT');
}
this.emit('resume');
};