-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (53 loc) · 1.75 KB
/
script.js
File metadata and controls
69 lines (53 loc) · 1.75 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
60
61
62
63
64
65
66
67
68
69
'use strict';
var childProcess = require('child_process');
var Mopidy = require('mopidy');
var path = require('path');
var mopidy = new Mopidy({
callingConvention: 'by-position-or-by-name',
webSocketUrl: 'ws://' + (process.env.HOST || 'localhost') + ':6680/mopidy/ws/'
});
var pifm = childProcess.spawn('ls', ['-l']);
// path is expected to be something like /home/pi/PiFmRds/src/pi_fm_rds
var pifmPath = require.resolve(path.join('/', 'home', 'pi', 'PiFmRds', 'src', 'pi_fm_rds'));
mopidy.on("event:trackPlaybackStarted", function (event) {
// catch the uri
var uri = event.tl_track.track.uri.split(":").pop();
console.log("-----------------------------------");
console.log("New song:", uri);
// kill
pifm.kill();
// sox.kill();
// respawn
// sox = childProcess.spawn("sox",["-t", "mp3", "/usr/share/tinyfm/media/" + uri, "-t", "wav", "-r", "22050", "-"]);
pifm = childProcess.spawn(pifmPath, ["-audio", "/usr/share/tinyfm/media/" + uri]);
// sox.stdout.on('data', function (data) {
// pifm.stdin.write(data);
// });
// sox.stderr.on('data', function (data) {
// console.log('sox stderr: ' + data);
// });
// sox.on('close', function (code) {
// if (code !== 0) {
// console.log('sox process exited with code ' + code);
// }
// pifm.stdin.end();
// });
pifm.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
pifm.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
pifm.on('close', function (code) {
console.log('child process exited with code ' + code);
});
// process.on('exit', function () {
// sox.kill();
// });
process.on('exit', function () {
pifm.kill();
});
}, logErrors);
function logErrors(err){
console.error(err);
}