yellowsnow2

Stuck in loop

Oct 24th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.io.*;
  2.  
  3.  
  4. void setup() {
  5.   size(400,400);
  6.   background(0);
  7.   textSize(50);
  8.   text("HI", 30, 50);
  9.  
  10.    
  11.  
  12. }
  13.  
  14. void draw(){
  15.  
  16.   play();
  17.   text("BYE", 30, 50);
  18.   exit();
  19. }
  20.  
  21. void play(){
  22.   //open mp4 file using xine media player
  23.   String commandToRun = "xine file:///home/me/sketchbook/webcam_capture/out.mp4" ;
  24.  
  25.  
  26.    File workingDir = new File("/bin");
  27.  
  28.     String returnedValues;                                                                     // value to return any results
  29.  
  30.   // give us some info:
  31.   println("Running command: " + commandToRun);
  32.   println("Location:        " + workingDir);
  33.   println("---------------------------------------------\n");
  34.  
  35.   // run the command!
  36.   try {
  37.  
  38.    
  39.     Process p = Runtime.getRuntime().exec(commandToRun, null, workingDir);
  40.      
  41.     // variable to check if we've received confirmation of the command
  42.     int i = p.waitFor();
  43.  
  44.     // if we have an output, print to screen
  45.     if (i == 0) {
  46.  
  47.       // BufferedReader used to get values back from the command
  48.       BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  49.  
  50.        //read the output from the command
  51.       while ( (returnedValues = stdInput.readLine ()) != null) {
  52.         println(returnedValues);
  53.        
  54.       }
  55.     }
  56.  
  57.     // if there are any error messages but we can still get an output, they print here
  58.     else {
  59.       BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  60.  
  61.       //if something is returned (ie: not null) print the result
  62.      while ( (returnedValues = stdErr.readLine ()) != null) {
  63.        println(returnedValues);
  64.       }
  65.     }
  66.   }
  67.  
  68.   // if there is an error, let us know
  69.  catch (Exception e) {
  70.     println("Error running command!");
  71.    println(e);
  72.  
  73.  
  74.   // when done running command, quit
  75.   println("\n---------------------------------------------");
  76.   println("DONE!");
  77.    exit();
  78.      
  79.   }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment