-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
bin.js
executable file
·65 lines (52 loc) · 1.27 KB
/
bin.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
var path = require('path')
var childProcess = require('child_process')
var FILENAME = path.join(__dirname, 'theme.mp3')
var bin = 'play'
var args = [FILENAME]
if (process.platform == 'darwin') bin = 'afplay'
if (process.platform == 'win32') {
bin = 'powershell'
args = ['-c', 'Add-Type -AssemblyName PresentationCore; ' +
'$MediaPlayer = New-Object System.Windows.Media.Mediaplayer; ' +
'$MediaPlayer.Open("' + FILENAME + '"); ' +
'$MediaPlayer.Play(); ' +
'Start-Sleep 273']
}
if (has('mplayer')) {
bin = 'mplayer'
args = ['-really-quiet', FILENAME]
}
var proc
var respawn = true
play()
function play () {
if (!respawn) return
proc = childProcess.spawn(bin, args)
proc.stdout.resume()
proc.stderr.resume()
proc.unref()
proc.on('exit', play)
if (process.argv[2]) {
proc.stdout.unref()
proc.stderr.unref()
proc.stdin.unref()
}
}
function has (cmd) {
try {
childProcess.execSync('which ' + cmd + ' 2>/dev/null 2>/dev/null')
return true
} catch (err) {
return false
}
}
if (process.argv[2]) {
childProcess.spawn(process.argv[2], process.argv.slice(3), {
stdio: 'inherit'
})
}
process.on('exit', function () {
respawn = false
proc.kill()
})