Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.io.UnsupportedEncodingException;
- import java.net.MalformedURLException;
- import java.nio.charset.Charset;
- import java.nio.charset.StandardCharsets;
- import javax.swing.JFrame;
- import org.apache.commons.codec.binary.Base64;
- import com.github.sarxos.webcam.Webcam;
- import com.github.sarxos.webcam.WebcamPanel;
- import com.github.sarxos.webcam.ds.ipcam.IpCamAuth;
- import com.github.sarxos.webcam.ds.ipcam.IpCamDeviceRegistry;
- import com.github.sarxos.webcam.ds.ipcam.IpCamDriver;
- import com.github.sarxos.webcam.ds.ipcam.IpCamMode;
- public class IpCameraTest {
- static {
- Webcam.setDriver(new IpCamDriver());
- }
- private static class AppWindow extends JFrame {
- /**
- * Serial.
- */
- private static final long serialVersionUID = 1L;
- public AppWindow() {
- setTitle("Demo app");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setResizable(false);
- setPreferredSize(new Dimension(640, 480));
- Webcam webcam = Webcam.getDefault();
- WebcamPanel panel = new WebcamPanel(webcam);
- add(panel);
- pack();
- setVisible(true);
- }
- }
- public static void main(String[] args) throws MalformedURLException {
- String name = "NC200";
- String url = "http://{ip-address}:8080/stream/getvideo";
- String user = "user";
- String password = encode("password");
- IpCamMode mode = IpCamMode.PUSH;
- IpCamAuth auth = new IpCamAuth(user, password);
- IpCamDeviceRegistry.register(name, url, mode, auth);
- new AppWindow();
- }
- private static String encode(String pwd) {
- final byte[] bytes = pwd.getBytes(StandardCharsets.UTF_8);
- final byte[] encoded = Base64.encodeBase64(bytes);
- try {
- return new String(encoded, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement