Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package lab12;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.concurrent.BlockingQueue;
  9. import javax.swing.JOptionPane;
  10. import lab12.Theora.ImagePlane;
  11.  
  12.  
  13. public class NetworkActor {
  14.     private static Boolean hasStarted = false;              //makes initializer run only once at startup
  15.    
  16.     private static URL url;
  17.     private static InputStream inputStream;
  18.     private static byte[] inputBuffer = new byte[100];
  19.     private static Theora.Context ctx;
  20.     private static int bytesRead;
  21.     //note: may need to create input buffer in the while loop
  22.     static void go(BlockingQueue<Object[]> Q) throws MalformedURLException, IOException, InterruptedException{
  23.         if (!hasStarted){
  24.             initialize();
  25.         }
  26.         System.out.println("link: " + url);
  27.         System.out.println("num bytes: " + inputStream.available());
  28.        
  29.         bytesRead = inputStream.read(inputBuffer, 0, 100);
  30.         //get byte array from inputStream and send it on
  31.         while (bytesRead > -1){
  32.             //puts the read data into the theora context buffer
  33.             //said data will be handled behind the scenes automatically by theora
  34.             ctx.enqueueData(inputBuffer, 0, bytesRead);        
  35.             bytesRead = inputStream.read(inputBuffer, 0, 100);
  36.         }                                                      
  37.     }
  38.    
  39.     static void initialize() throws MalformedURLException, IOException, InterruptedException{
  40.         //Prompt for a URL
  41.         //String x = JOptionPane.showInputDialog("Site?");                      //CHANGE THIS BEFORE TURNING IN
  42.         //url = new URL(x);
  43.         url = new URL("http://selenium.ssucet.org/04.OGG");
  44.         URLConnection c = url.openConnection();
  45.         //Creates input stream of data
  46.         inputStream = c.getInputStream();
  47.         //Creates theora context to pass to decoder on its init
  48.         ctx = new Theora.Context();
  49.         Lab11.queues.get("DecodeActor").put(new Object[] {ctx});
  50.        
  51.         System.out.println("Initialized network actor");
  52.         hasStarted = true;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement