Memory Card Recording

Last Updated on : 2024-06-19 04:10:51download

Users can view recorded footage from the smart camera’s memory card on the app through the IPC SDK.

You need to do the following before starting playback:

  1. Create an IThingSmartCameraP2P object and connect to the peer-to-peer (P2P) channel.

  2. Once the P2P channel is established, users can search for video clips on the camera’s memory card by time frame and play them.

  3. During playback, users can access audio and video features like starting/stopping recording, screenshot, and muting sound. For more information, see Audio and Video.

    Memory Card Recording

Core methods

Demo Class Method Description Notes
IThingSmartCameraP2P queryRecordDaysByMonth Query the dates when recordings exist. Before playback, query the dates when recordings exist in the specified month and year.
IThingSmartCameraP2P queryRecordTimeSliceByDay Query video clips on the specified date. After obtaining the dates when video clips exist, query the clips by date.
IThingSmartCameraP2P startPlayBack Start playback. Error codes
IThingSmartCameraP2P stopPlayBack Stop playback. -
IThingSmartCameraP2P disconnect Disconnect. When not in use, disconnect the P2P connection to free up resources.

Important notes

It is recommended not to call other methods of the IThingSmartCameraP2P object within this object’s callback, which may be asynchronously called. Otherwise, a deadlock might occur.

Core code

Query the dates when recordings exist

void queryRecordDaysByMonth(int year, int month, OperationDelegateCallBack callBack);

Query video clips by date

void queryRecordTimeSliceByDay(int year, int month, int day, OperationDelegateCallBack callBack);

Start playback

void startPlayBack(int startTime, int stopTime, int playTime, OperationDelegateCallBack callBack, OperationDelegateCallBack finishCallBack);

Stop playback

void stopPlayBack(OperationDelegateCallBack callBack);

Java:

// 1. Create IThingSmartCameraP2P
IThingSmartCameraP2P mCameraP2P = null;
IThingIPCCore cameraInstance = ThingIPCSdk.getCameraInstance();
if (cameraInstance != null) {
    mCameraP2P = cameraInstance.createCameraP2P(devId));
}
ThingCameraView mVideoView = findViewById(R.id.camera_video_view);
// 2. Set the callback for the view rendering container.
mVideoView.setViewCallback(new AbsVideoViewCallback() {
    @Override
    public void onCreated(Object view) {
        super.onCreated(view);
        // When the rendering view is constructed, bind it to IThingSmartCameraP2P.
        if (null != mCameraP2P){
            mCameraP2P.generateCameraView(view);
        }
    }
});
// 3. Construct the rendering view.
mVideoView.createVideoView(devId);
// 4. Register a listener for P2P.
AbsP2pCameraListener absP2pCameraListener = new AbsP2pCameraListener() {
    @Override
    public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
            super.onSessionStatusChanged(camera, sessionId, sessionStatus);
            // When sessionStatus = -3 (timeout) or -105 (authentication failed), try reconnecting and avoid loop.
            }
};
if (null != mCameraP2P){
    mCameraP2P.registerP2PCameraListener(absP2pCameraListener);
}
// 5. Connect to P2P.
if (null != mCameraP2P){
mCameraP2P.connect(devId, new OperationDelegateCallBack() {
    @Override
    public void onSuccess(int sessionId, int requestId, String data) {
        // Connection successful. Send a message to the handler to return to the main thread and then initiate streaming.
    }

    @Override
    public void onFailure(int sessionId, int requestId, int errCode) {
        // Connection failed.
    }
});
}
// 6. Start playback.
if (null != mCameraP2P){
mCameraP2P.startPlayBack(timePieceBean.getStartTime(),
                         timePieceBean.getEndTime(),
                         timePieceBean.getStartTime(), new OperationDelegateCallBack() {
                           @Override
                           public void onSuccess(int sessionId, int requestId, String data){
                             isPlayback = true;
                           }

                           @Override
                           public void onFailure(int sessionId, int requestId, int errCode){
                             isPlayback = false;
                           }
                         }, new OperationDelegateCallBack() {
                           @Override
                           public void onSuccess(int sessionId, int requestId, String data){
                             isPlayback = false;
                           }

                           @Override
                           public void onFailure(int sessionId, int requestId, int errCode){
                             isPlayback = false;
                           }
                         });
}
// 7. Stop releasing P2P sessions when the page is closed or playback is not used.
@Override
public void onDestroy() {
    if (null != mCameraP2P) {
        // Stop playback when not needed.
        mCameraP2P.stopPlayBack(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {

  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {

  }
});
        mCameraP2P.disconnect(devId,null);
        mCameraP2P.removeOnP2PCameraListener(absP2pCameraListener);
        mCameraP2P.destroyP2P();
    }
}