Search code examples
androidip-camera

Accessing the live stream of an IP camera (Dlink 930l) with authentication on Android


I have an IPCamera (Dlink DCS930l) connected to a network which requires authentication to access the stream.

Are there any Android libraries or frameworks that have the functionality to access an authenticated network stream?


Solution

  • I was able to do something similar with a GoPro via Wifi connection.

    Method 1: This can be achieved using OpenCV. Based on the type of authentication used, you will need to specify the corresponding protocol, username and password when you provide the IP to access the camera. The syntax required to open the camera stream using OpenCV is provided here (1).

    You will need to use OpenCV for Android and JNI bindings to the native C++ OpenCV API. Some sample applications here demonstrate how to make calls to the native API in an Android project.

    xuchong has developed a sample Android application demonstrating how to read an mp4 file natively via OpenCV on Android. Update the video path in the MainActivity.java OnCreate() method to the IP camera feed with the syntax from (1) to read from a camera requiring authentication.

    Method 2: An example application demonstrating an alternative method that does not use OpenCV but instead uses the mjpeg library can be found here.

    Method 3: Using just VideoView, assuming you have a http stream using Basic Auth for authentication, you can set headers when you provide the URI link in the following way:

    Map<String, String> params = new HashMap<String, String>(1);
    byte[] toEncrypt = (username + ":" + password).getBytes();
    String encoded = Base64.encodeToString(toEncrypt, Base64.DEFAULT);
    final String auth = "Basic " + encoded;
    params.put("Authorization", auth);
    Log.e(TAG, "Params Encode: " + params);
    myVideoView.setVideoURI(vidAddress, params);