Browse files

audioworky

  • Loading branch information...
2 parents 7efa33a + 87ed26b commit be30d6daf75ff87a1998089c5c6522d3ab559c12 @LindseyB LindseyB committed Oct 24, 2010
Showing with 55 additions and 28 deletions.
  1. +9 −9 AAR.d
  2. +46 −19 util/soundclip.d
View
18 AAR.d
@@ -13,16 +13,16 @@ WINDOW* win;
WINDOW* message;
void main(){
- /*SoundClip sc = new SoundClip("music/ID__Baobinga_-_10_-_Raise_Riddim.mp3");
+ SoundClip sc = new SoundClip("music/ID__Baobinga_-_10_-_Raise_Riddim.mp3");
sc.start();
- Stdout("started playing\n");
- Thread.sleep(1000);
- Stdout("done with sleep\n");
- Stdout.format("{}\n", sc.pause());
- Thread.sleep(1000);
- Stdout.format("{}\n", sc.unpause());
- Thread.sleep(1000);
- Stdout.format("{}\n", sc.stop());*/
+ Stdout("started playing\n")();
+ Thread.sleep(5);
+ Stdout("done with sleep\n")();
+ Stdout.format("{}\n", sc.pause())();
+ Thread.sleep(5);
+ Stdout.format("{}\n", sc.unpause())();
+ Thread.sleep(5);
+ Stdout.format("{}\n", sc.stop())();
initscr();
noecho();
View
65 util/soundclip.d
@@ -4,62 +4,89 @@ 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;
+ //pid_t pid
bool paused;
+ Process p;
+
public:
this(char[] fn){
exe = "cvlc";
filename = fn;
- pid = 0;
}
bool start(){
- if(pid != 0){return false;}
+ if(p !is null){return false;}
- if((pid = fork()) == 0){
- char[] temp = exe ~ filename;
-
- execlp(toStringz(exe), toStringz(exe), toStringz(filename), cast(void*)null);
+ //if((pid = fork()) == 0){
+ char[] temp = exe ~ ' ' ~ filename;
+
+ try{
+ p = new Process (temp, null);
+ p.copyEnv(true);
- }else{
+ 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){
+ //if(pid > 0){
- return true;
- }else{
- return false;
- }
- }
+ // return true;
+ //}else{
+ // return false;
+ //}
+ //}
+
+ return true;
}
bool stop(){
- if(pid == 0){return false;}
+ if(p is null){return false;}
- if(kill(pid, SIGKILL) != 0){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(pid == 0 || paused){return false;}
+ if(p !is null || paused){return false;}
+
return signal(SIGSTOP);
}
bool unpause(){
- if((pid == 0) || !paused){return false;}
+ if((p !is null) || !paused){return false;}
+
return signal(SIGCONT);
}
bool signal(int sig){
- return (kill(pid, sig) == 0);
+ return (kill(p.pid, sig) == 0);
}
}

0 comments on commit be30d6d

Please sign in to comment.