Skip to content

Commit

Permalink
audioworky
Browse files Browse the repository at this point in the history
  • Loading branch information
LindseyB committed Oct 24, 2010
2 parents 7efa33a + 87ed26b commit be30d6d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 28 deletions.
18 changes: 9 additions & 9 deletions AAR.d
Expand Up @@ -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();
Expand Down
65 changes: 46 additions & 19 deletions util/soundclip.d
Expand Up @@ -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.