forked from LindseyB/AsciiAsciiRevolution
/
soundclip.d
92 lines (66 loc) · 1.46 KB
/
soundclip.d
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module util.soundclip;
import tango.stdc.posix.unistd;
import tango.stdc.posix.signal;
import tango.stdc.stringz;
//import tango.std.posix.stdlib;
import tango.sys.Process;
import tango.io.Stdout;
class SoundClip{
private:
char[] exe;
char[] filename;
//pid_t pid
bool paused;
Process p;
public:
this(char[] fn){
exe = "cvlc";
filename = fn;
}
bool start(){
if(p !is null){return false;}
//if((pid = fork()) == 0){
char[] temp = exe ~ ' ' ~ filename;
try{
p = new Process (temp, null);
p.copyEnv(true);
p.setRedirect(Redirect.All);
p.execute;
}
catch (Exception e){
Stdout.formatln ("Process execution failed: {}", e);
return false;
}
//execlp(toStringz(exe), toStringz(exe), toStringz(filename), cast(void*)null);
//}else{
// ???
//if(pid > 0){
// return true;
//}else{
// return false;
//}
//}
return true;
}
bool stop(){
if(p is null){return false;}
//if(kill(pid, SIGKILL) != 0){return false;}
//XXX: wait for child zombie
p.kill();
//auto result = p.wait;
//Stdout.formatln ("Process '{}' ({}) exited with reason {}, status {}",
// p.programName, p.pid, cast(int) result.reason, result.status);
return true;
}
bool pause(){
if(p !is null || paused){return false;}
return signal(SIGSTOP);
}
bool unpause(){
if((p !is null) || !paused){return false;}
return signal(SIGCONT);
}
bool signal(int sig){
return (kill(p.pid, sig) == 0);
}
}