English
English
简体中文
Contact Us
Register
Log In
layoutIndex

SD Card-Stored Video Playback

Last Updated on : 2022-03-01 13:41:39download

IP cameras (IPCs) support recording and playback of video footage that is stored on SD cards. You can integrate with the IPC SDK to develop these features for your app. After an SD card is inserted into an IPC, users can view the details and status of the SD card and set the recording switch and mode on the app.

Functional description

After video footage is saved to an SD card, it can be played back on the app based on the IPC SDK. For more information, see SD Card Management.

Similar to live video streaming, a P2P connection must be created before video footage playback. Perform the following steps:

  1. Create an ITuyaSmartCameraP2P object to build a P2P connection.

  2. Through a P2P connection, you can implement querying information about video footage stored on an SD card and playing back desired video clips.

  3. After video playback is started, additional audio and video features can be implemented. For example, start or stop video recording, capture video screenshots, and enable or disable video sound. For more information, see Audio and Video Features.

    SD Card-Stored Video Playback

Video clips

The IPC SDK supports query and playback of SD card-stored video footage by day. Users can also query the days on which video footage is available in a certain month.

Query days with video footage stored in a month

Returns the days on which video footage is available in a certain month before video playback.

API description

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

Parameters

Parameter Description
year The year to be queried.
month The month to be queried.
monthcallBack The callback.

Example

int year = Integer.parseInt(substring[0]);
int mouth = Integer.parseInt(substring[1]);
queryDay = Integer.parseInt(substring[2]);
mCameraP2P.queryRecordDaysByMonth(year, mouth, new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    // `data` indicates the returned days of the month.
    MonthDays monthDays = JSONObject.parseObject(data, MonthDays.class);
    mBackDataMonthCache.put(mCameraP2P.getMonthKey(), monthDays.getDataDays());
    mHandler.sendMessage(MessageUtil.getMessage(MSG_DATA_DATE, ARG1_OPERATE_SUCCESS, data));
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {
    mHandler.sendMessage(MessageUtil.getMessage(MSG_DATA_DATE, ARG1_OPERATE_FAIL));
  }
});

Query all video clips stored on a day

Returns a list of video footage on the days returned in the previous step.

API description

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

Parameters

Parameter Description
year The year to be queried.
month The month to be queried.
day The day to be queried.
callBack The callback.

Example

int year = Integer.parseInt(substring[0]);
int mouth = Integer.parseInt(substring[1]);
int day = Integer.parseInt(substring[2]);
mCameraP2P.queryRecordTimeSliceByDay(year, mouth, day, new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    // `data` indicates the list of returned video clips for the specified date.
    parsePlaybackData(data);
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {
    mHandler.sendEmptyMessage(MSG_DATA_DATE_BY_DAY_FAIL);
  }
});

parsePlaybackData(data) reference

private void parsePlaybackData(Object obj) {
        RecordInfoBean recordInfoBean = JSONObject.parseObject(obj.toString(), RecordInfoBean.class);
        if (recordInfoBean.getCount() != 0) {
            List<TimePieceBean> timePieceBeanList = recordInfoBean.getItems();
            if (timePieceBeanList != null && timePieceBeanList.size() != 0) {
                mBackDataDayCache.put(mCameraP2P.getDayKey(), timePieceBeanList);
            }
            mHandler.sendMessage(MessageUtil.getMessage(MSG_DATA_DATE_BY_DAY_SUCC, ARG1_OPERATE_SUCCESS));
        } else {
            mHandler.sendMessage(MessageUtil.getMessage(MSG_DATA_DATE_BY_DAY_FAIL, ARG1_OPERATE_FAIL));
        }
    }

Data model of RecordInfoBean

Parameter Description
count The number of video clips.
List The list of video clips.

Data model of TimePieceBean

Parameter Description
startTime The start time of a video clip.
endTime The end time of a video clip.
playTime The time from which playback of a video clip is started.

Video playback

Start playback

API description

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

Parameters

Parameter Description
startTime The 10-digit start timestamp.
stopTime The end time.
playTime The time from which video footage playback is started.
callBack The callback that is executed when video playback is started.
finishcallBack The callback that is executed when video playback is finished.

Example

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;
                           }
                         });

Pause playback

API description

void pausePlayBack(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

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

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

  }
});

Resume playback

API description

void resumePlayBack(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

mCameraP2P.resumePlayBack(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    isPlayback = true;
  }

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

  }
});

Stop playback

API description

void stopPlayBack(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

mCameraP2P.stopPlayBack(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {

  }

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

  }
});

Set playback speed

Certain IPCs support playback of video footage stored on an SD card at a specified speed. You can use the device capability class ICameraConfigInfo to query the list of playback speeds supported by the device.

API description

void setPlayBackSpeed(int speed, OperationDelegateCallBack callBack);

Parameters

Parameter Description
speed The video footage playback speed that must be supported by the device.
callBack The callback.

Video download

Certain IPCs support downloading video footage stored on an SD card to the app. You can call the API method of the IPC SDK to check whether an IPC supports downloading SD card-stored video footage.

Query support for video download

API description

Checks whether the device supports downloading video footage from an SD card to the app. This method is called only after a P2P connection is created.

boolean isSupportPlaybackDownload();

Example

ITuyaIPCCore cameraInstance = TuyaIPCSdk.getCameraInstance();
if (cameraInstance != null) {
    ICameraConfigInfo cameraConfig = cameraInstance.getCameraConfig(devId);
    if (cameraConfig != null) {
        boolean supportPlaybackDownload = cameraConfig.isSupportPlaybackDownload();
    }
}

Start downloading video footage

API description

void startPlayBackDownload(int startTime, int stopTime, String folderPath, String fileName, OperationDelegateCallBack callBack, ProgressCallBack progressCallBack, OperationDelegateCallBack finishCallBack);

Parameters

Parameter Description
startTime The start time.
stopTime The end time.
folderPath The path through which the video clips are stored.
fileName The name of the video file.
callBack The callback.
progressCallBack The callback for the download progress.
finishCallBack The callback that is used when the download task is finished.

Due to the limited file retrieval capability of IPCs, the video footage to be downloaded must belong to a video clip. The start time (startTime) and end time (stopTime) of the target video footage fall within the period of a video clip.

Pause video downloading

API description

void pausePlayBackDownload(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Resume video downloading

API description

void resumePlayBackDownload(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Stop video downloading

API description

void stopPlayBackDownload(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Video deletion

Certain IPCs support deleting video footage from an SD card. The deletion is controlled on the app. Currently, video footage can be deleted only by date.

Query support for video deletion

API description

Checks whether the device supports deleting video footage from an SD card. This method is called only after a P2P connection is created.

boolean isSupportPlaybackDelete();

Example

ITuyaIPCCore cameraInstance = TuyaIPCSdk.getCameraInstance();
if (cameraInstance != null) {
    ICameraConfigInfo cameraConfig = cameraInstance.getCameraConfig(devId);
    if (cameraConfig != null) {
        boolean supportPlaybackDelete = cameraConfig.isSupportPlaybackDelete();
    }
}

Delete videos stored on a specified date

API description

void deletePlaybackDataByDay(String day, OperationDelegateCallBack callBack, OperationDelegateCallBack finishCallBack);

Parameters

Parameter Description
day The date in the format of yyyy-MM-dd.
callBack The callback.
finishCallBack The callback that is used when the deletion task is finished.