Advertisement
Guest User

TP-Link NC200 Webcam Capture Demo

a guest
Apr 7th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.awt.Dimension;
  2. import java.io.UnsupportedEncodingException;
  3. import java.net.MalformedURLException;
  4. import java.nio.charset.Charset;
  5. import java.nio.charset.StandardCharsets;
  6.  
  7. import javax.swing.JFrame;
  8.  
  9. import org.apache.commons.codec.binary.Base64;
  10.  
  11. import com.github.sarxos.webcam.Webcam;
  12. import com.github.sarxos.webcam.WebcamPanel;
  13. import com.github.sarxos.webcam.ds.ipcam.IpCamAuth;
  14. import com.github.sarxos.webcam.ds.ipcam.IpCamDeviceRegistry;
  15. import com.github.sarxos.webcam.ds.ipcam.IpCamDriver;
  16. import com.github.sarxos.webcam.ds.ipcam.IpCamMode;
  17.  
  18. public class IpCameraTest {
  19.    
  20.     static {
  21.         Webcam.setDriver(new IpCamDriver());
  22.     }
  23.    
  24.     private static class AppWindow extends JFrame {
  25.  
  26.         /**
  27.          * Serial.
  28.          */
  29.         private static final long serialVersionUID = 1L;
  30.        
  31.         public AppWindow() {
  32.            
  33.             setTitle("Demo app");
  34.             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35.             setResizable(false);
  36.             setPreferredSize(new Dimension(640, 480));
  37.            
  38.             Webcam webcam = Webcam.getDefault();
  39.             WebcamPanel panel = new WebcamPanel(webcam);
  40.            
  41.            
  42.            
  43.             add(panel);
  44.             pack();
  45.             setVisible(true);
  46.         }
  47.     }
  48.    
  49.     public static void main(String[] args) throws MalformedURLException {
  50.        
  51.         String name = "NC200";
  52.         String url = "http://{ip-address}:8080/stream/getvideo";
  53.    
  54.         String user = "user";
  55.         String password = encode("password");
  56.         IpCamMode mode = IpCamMode.PUSH;
  57.         IpCamAuth auth = new IpCamAuth(user, password);
  58.    
  59.        
  60.         IpCamDeviceRegistry.register(name, url, mode, auth);
  61.        
  62.         new AppWindow();
  63.        
  64.     }
  65.  
  66.     private static String encode(String pwd) {
  67.         final byte[] bytes = pwd.getBytes(StandardCharsets.UTF_8);
  68.         final byte[] encoded = Base64.encodeBase64(bytes);
  69.         try {
  70.             return new String(encoded, "UTF-8");
  71.         } catch (UnsupportedEncodingException e) {
  72.             throw new IllegalStateException(e);
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement