中文简体    English


Aiwei IoT SDK usage documentation on Android

side takes the construction of the Android-app-sdk-demo project as an example, (IDE is
Androidstudio, AS), to introduce the SDK docking process for developers.
Click to download

Quick access

  1. Download the demo compressed package and unzip it
  2. Copy the aar file under libs to the directory corresponding to your own project
  3. Build.gradle introduces the following code The AS project
    dependencies {
     ...
     implementation(name: 'ipclibrary-2021_12_13', ext: 'aar')
    }
    directory after adding is as follows:

Ivyiot-android-sdk is a sdk package that Ivyiot helps third-party developers to quickly implement the use of ipc on the Android App side. It includes an introduction to the API usage of several parts of initializing sdk, connecting to ipc, controlling ipc, live audio and video, and playback of audio and video.

SDK initialization It is

generally recommended to initialize in the application.

/** Set the SDK log storage path and log level. The official release level is set to LogLevel.NO*/
 SDKManager.getInstance().setLog(logFilePath, LogLevel.ALL);//called before init
 /** Initialization, it must be placed before using the SDK, and it only needs to be called once globally*/
 SDKManager.getInstance().init(this);

The main process of the SDK


Connect the device

Steps

  1. After the initial device is powered on, configure the network (QR code scanning, sound wave)
  2. After the device is successfully connected to the network, SDKManager.getInstance().discoveryDeviceInWLANobtain the device UID and other information
  3. Create an IvyCamera object, you must assign the UID and the user name of the device ( usrName, the initial value is admin), the password of the device (password, the initial password can be SDKManager.getInstance().getFactoryPasswordobtained)
  4. Call IvyCamera.loginDeviceto realize the connection
  5. Call to IvyCamera.destroyrelease the connection

Scan the QR code to configure the network

In the initial state, the camera of the device scans the QR code to configure the network

  1. Pass the wifi ssid and password to SDKManager.getInstance().createQRInfocreate text information
  2. Based on this text information, generate the corresponding QR code image for the device to scan, and wait for the device to play the voice of the successful scan code After the prompt, wait for the device to connect to the network.
  3. During this period, the APP can call SDKManager.getInstance().discoveryDeviceInWLANthe method in a loop until the specified device is found, which means the network configuration is successful (you can compare and filter the uid of the searched device and the uid information on the device body).

    Note:
    This sdk does not provide the function of recognizing QR code and generating QR code images. APP developers can implement it by themselves through a third-party library (zxing).

Sonic distribution network

Play the sound wave information on the mobile phone and let the device in the initial state receive it

  1. Use the wifi ssid and password to play the corresponding sound wave information through SDKManager.getInstance().startSoundWaveAdd
  2. After playing the sound wave and wait for the voice prompt of the device to be successfully connected to the network, wait for the device to connect to the network
  3. In During this period, the APP can call the method in a loop SDKManager.getInstance().discoveryDeviceInWLANuntil the specified device is searched, which means the network configuration is successful (you can compare and filter the uid of the searched device and the uid
    information on the device body).

LAN search

Search for the networked devices currently connected to wifi on the
mobile phone 1. Call SDKManager.getInstance().discoveryDeviceInWLANto
get all devices under the current LAN

Live playback

Step

  1. Create a player and introduce the following code into the layout
<com.ivyiot.ipclibrary.video.VideoSurfaceView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp" />
  1. Call IvyCamera.loginDeviceto connect to log in to the device
  2. After successful login, call to VideoSurfaceView.openVideostart real-time playback
  3. When closing or leaving the interface, you need to call VideoSurfaceView.closeVideoclose to release resources

The example code is as

    ...
   camera.loginDevice(new ISdkCallback() {
                @Override
                public void onSuccess(Object result) {
                    //Open the video, the command result is received through the callback method, see IVideoListener
                    videoview.openVideo(camera, this);
                }

                @Override
                public void onError(int errorCode) {

                }

                @Override
                public void onLoginError(int errorCode) {

                }
            });
            ...
   if (null != videoview) {//close Video
        videoview.closeVideo();
    }

instruction

  1. After the real-time playback is successful, the following operations can be performed: video recording, photographing, screen flipping, intercom, PTZ control, monitoring, etc., among which the device controls the interface such as PTZ control and lens display functions, intercom, which belong to the restricted level interface. It is preferable to call by judging the capability set of the device. For the device capability set, please check DevAbilitythe attribute value of the object to judge the specific method.
//Start recording. It is valid only after the video stream data is successfully obtained.
//filePath The full path where the video file is stored (including the file name and the suffix is .mp4)
IvyCamera.startRecord(filePath, new ISdkCallback(){});

//stop recording
IvyCamera.stopRecord(new ISdkCallback(){});

//Whether the capture function hasSound included in the player needs to capture sound
VideoSurfaceView.snap(boolean hasSound)


 /**
     * 
Get mirror rollover settings for ipc
     *
     * @param callback The callback returns an Integer array containing two elements, the first is the switch state of mirror, and the second is the switch state of flip. 1 means on, 0 means off.
     */
IvyCamera.getMirrorAndFlip(new ISdkCallback<Integer[]>(){})
    /**
     * Set the video flip switch
     *
     * @param enable 1 on, 0 off
     */
IvyCamera.setFlip(int enable, ISdkCallback<Integer> callback)
    /**
     * Set the video mirroring switch
     *
     * @param enable 1 on, 0 off
     */
IvyCamera.setMirror(int enable, ISdkCallback<Integer> callback)

//Open talk
IvyCamera.openTalk(new ISdkCallback() {
                        @Override
                        public void onSuccess(Object result) {
                            if (null == talkThread) {//Send the information collected by the MIC to the device
                                talkThread = new TalkThread(IvyCamera, true);
                                talkThread.startTalk();
                                talkThread.start();
                            }
                        }

                        @Override
                        public void onError(int errorCode) {

                        }

                        @Override
                        public void onLoginError(int errorCode) {

                        }
                    });

//Close talk
IvyCamera.closeTalk(new ISdkCallback() {
                    @Override
                    public void onSuccess(Object result) {
                        if (null != talkThread) {//stop sending data
                            talkThread.stopTalk();
                            talkThread = null;
                        }
                    }

                    @Override
                    public void onError(int errorCode) {

                    }

                    @Override
                    public void onLoginError(int errorCode) {

                    }
                });

//Open audio
    IvyCamera.openAudio(new ISdkCallback() {
                    @Override
                    public void onSuccess(Object result) {
                        if (null == audioThread) {//Play audio
                            audioThread = new AudioThread(camera, true);
                            audioThread.startAudio();
                            audioThread.start();
                        }
                    }

                    @Override
                    public void onError(int errorCode) {

                    }

                    @Override
                    public void onLoginError(int errorCode) {

                    }
                });
//close audio
IvyCamera.closeAudio(new ISdkCallback() {
                    @Override
                    public void onSuccess(Object result) {
                        if (null != audioThread) {//stop audio
                            audioThread.stopAudio();
                            audioThread = null;
                        }
                    }

                    @Override
                    public void onError(int errorCode) {
                    }

                    @Override
                    public void onLoginError(int errorCode) {
                    }
                });
  1. PTZ control, after sending the corresponding direction command, you need to call stop once to end the operation. It is recommended to use the onTouch event of the control to handle it.

    //For details of control commands, see PTZCmd
    @Override
    public boolean onTouch(View v, MotionEvent event) {
     try {
         switch (event.getAction()) {
             case MotionEvent.ACTION_DOWN: {// XXX MotionEvent.ACTION_DOWN
                 switch (v.getId()) {
                     case "ptz_up":
                         IvyCamera.ptzControl(PTZCmd.PTZ_MOVE_UP, null);
                         break;
                     case "ptz_down":
                         IvyCamera.ptzControl(PTZCmd.PTZ_MOVE_DOWN, null);
                         break;
                     case "ptz_left":
                         IvyCamera.ptzControl(PTZCmd.PTZ_MOVE_LEFT, null);
                         break;
                     case "imgbtn_ptz_right":
                         IvyCamera.ptzControl(PTZCmd.PTZ_MOVE_RIGHT, null);
                         break;
                     case "ptz_center":
                         IvyCamera.ptzControl(PTZCmd.PTZ_RESET, null);
                         break;
                 }
             }
             break;
             case MotionEvent.ACTION_UP:
             case MotionEvent.ACTION_CANCEL: {
                 switch (v.getId()) {
                     case "ptz_up":
                     case "ptz_down":
                     case "ptz_left":
                     case "ptz_center":
                         IvyCamera.ptzControl(PTZCmd.PTZ_STOP, null);
                         break;
                 }
             }
             break;
         }
     } catch (Exception ex) {
         ex.printStackTrace();
     }
     return false; // return false the system will continue processing
    }
  2. Switch clarity

...
    // 1、Subscribe to device events
    IvyCamera.addObserver(this);
//2、get device info
IvyCamera.getDevInfo(new ISdkCallback(){});
//3、Get Device Capability Set
IvyCamera.getDevAbility(new ISdkCallback(){});
//4、Get clarity options
EDefinitionItem.EResolutionMode[] definitionItem = IvyCamera.getDefinitionItems(DevAbility, DevInfo);
//5、Get the gear of the current video stream in the observer monitor, corresponding to the array subscript of the resolution option
@Override
    public void update(Observable o, Object arg) {
    if (arg != null) {
        Message msg = (Message) arg;
        Log.e(TAG, "update: " + msg.what + ";data=" + msg.obj);
        switch (msg.what){
            case EventID.IVY_CTRL_MSG_VIDEO_STREAM_MODE:
            //subscript corresponding to clarity
            int hdsdValue = (int) msg.obj;
            break;
        }
    }
}
//6、set clarity
boolean streamMode = definitionItem.length == 2 && !CommonUtil.is313EPlatform(devAbility);
if (streamMode) {//Main/substream switching
    changeStream(1);
    if (index == 0) {
        IvyCamera.setStreamType(StreamMode.STREAM_MAIN);
    } else {
        IvyCamera.setStreamType(StreamMode.STREAM_SUB);
    }
    VideoSurfaceView.closeVideo();
    VideoSurfaceView.openVideo(camera, this);
} else {//three gear switch
    IvyCamera.changeDefinition(0, new ISdkCallback(){});
}
//Unsubscribe from device message events
IvyCamera.deleteObserver(this);
...

SD card playback

Step

  1. Create a player and introduce the following code into the layout
<com.ivyiot.ipclibrary.video.PBVideoSurfaceView
    android:id="@+id/pbvideoview"
        android:layout_width="match_parent"
            android:layout_height="260dp"
                android:layout_marginTop="3dp" />
  1. Query the recording files in the device in the SD card according to the date and type
//Note: The month of the Calendar class starts from 0
Calendar cal = Calendar.getInstance();
//2019.9.23 00:00:00
cal.set(2022, 0, 5, 0, 0, 0);
int todayStart = (int) (cal.getTimeInMillis() / 1000);
//2019.9.23 23:59:59
cal.set(2022, 0, 5, 23, 59, 59);
int todayEnd = (int) (cal.getTimeInMillis() / 1000);
/**
  * Get a list of sd recording files within a period of time.
  * <br>
  * Since the maximum number of videos in a day can exceed 1000, it is recommended to query by time period, and the query period should not exceed one day.
  *
  * @param startTime  Search start time (UTC time, accurate to seconds)
  * @param endTime    Search end time (UTC time, accurate to seconds)
  * @param recordType File Type: 0 schedule, 1 alert, 2 all
  */
IvyCamera.getPBList(todayStart, todayEnd, recordType, new ISdkCallback<ArrayList<PlaybackRecordInfo>>() {

    @Override
        public void onSuccess(ArrayList<PlaybackRecordInfo> result) {
        recordIvyArr = result;
        Log.e(TAG, "onSuccess: " + recordIvyArr.size());
    }

    @Override
        public void onError(int errorCode) {
        Log.e(TAG, "onError: " + errorCode);
    }

    @Override
        public void onLoginError(int errorCode) {
    }
});
  1. Select the queried video file and call PBVideoSurfaceView.openPBVideo(IvyCamera, recordIvyArr.get(position), this)to open playback;
  2. Call to PBVideoSurfaceView.closePBVideo()close the current playback video;
文档更新时间: 2022-02-28 15:52   作者:庄小婵