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

Cloud Storage

Last Updated on : 2022-09-20 08:39:37download

IP cameras (IPCs) support the cloud storage service that allows users to save video footage on the IPCs to the cloud.

Process

  1. First, get the cloud storage service status.
  2. Perform steps based on the service status:
    • If the cloud storage service is unactivated or has expired, the cloud storage service must be purchased to enable the cloud storage service.

      After the cloud storage service expires, the existing cloud-stored video files will be retained for a period, seven days in most cases. At the end of this period, all cloud-stored video files will be deleted.

    • If the cloud storage service is within the validity period:

      1. Get the date on which the cloud-stored video files were created.
      2. Get the data of the specified date, including cloud storage events, timeline data, and authentication information.
      3. Select a cloud storage event or a time point to start cloud-stored video playback.
      Cloud Storage

Subscription

To enable subscription to the cloud storage service, the Cloud Storage UI BizBundle must be integrated. This component provides the H5 pages and order display features for the subscription.

Cloud storage object

ITYCloudCamera provides API methods to deal with cloud-stored video footage.

API description

Creates a cloud storage instance object.

ITYCloudCamera createCloudCamera();

Example

private ITYCloudCamera cloudCamera;

ITuyaIPCCloud cloud = TuyaIPCSdk.getCloud();
if (cloud != null) {
    cloudCamera = cloud.createCloudCamera();
}

Cloud storage data

Get cloud storage status

API description

void queryCloudServiceStatus(String devId, ITuyaResultCallback<CloudStatusBean> callback);

Parameters

Parameter Description
devId The device ID.
callback The callback.

Example

cloudCamera.queryCloudServiceStatus(devId, new ITuyaResultCallback<CloudStatusBean>() {
    @Override
    public void onSuccess(CloudStatusBean result) {
        //Get cloud storage status
    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Data model of CloudStatusBean

Parameter Description
status The status code. Valid values:
  • 10001: The cloud storage service is not purchased.
  • 10010: The cloud storage service has already been activated.
  • 10011: The cloud storage service has expired.

Query cloud-stored video date

API description

void getCloudDays(String devId, String timezoneId, ITuyaResultCallback<List<CloudDayBean>> callback);

Parameters

Parameter Description
devId The device ID.
timezoneId The time zone ID.

Example

cloudCamera.getCloudDays(devId, TimeZone.getDefault().getID(), new ITuyaResultCallback<List<CloudDayBean>>() {
    @Override
    public void onSuccess(List<CloudDayBean> result) {

    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Data model of CloudDayBean

Parameter Description
uploadDay The date.
currentDayStart The start time of a period in which video clips are returned.
currentDayEnd The end time of a period in which video clips are returned.

Query video clips within a specified period

API description

void getTimeLineInfo(String devId, long timeGT, long timeLT, ITuyaResultCallback<List<TimePieceBean>> callback);

Parameters

Parameter Description
devId The device ID.
timeGT The 10-digit start timestamp.
timeLT The 10-digit end timestamp.
callback The callback.

Example

CloudDayBean dayBean = dayBeanList.get(0);
cloudCamera.getTimeLineInfo(devId, dayBean.getCurrentStartDayTime(), dayBean.getCurrentDayEndTime(), new ITuyaResultCallback<List<TimePieceBean>>() {
    @Override
    public void onSuccess(List<TimePieceBean> result) {

    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Query motion detection data within a specified period

API description

void getMotionDetectionInfo(String devId, long timeGT, long timeLT, int offset, int limit, ITuyaResultCallback<List<TimeRangeBean>> callback);

Parameters

Parameter Description
devId The device ID.
timeGT The 10-digit start timestamp.
timeLT The 10-digit end timestamp.
offset The page number starting from which target data is returned. Default value: 0.
limit The maximum number of entries to be returned at a time. Default value: -1 to return all data.
callback The callback.

Example

CloudDayBean dayBean = dayBeanList.get(0);
cloudCamera.getMotionDetectionInfo(devId, dayBean.getCurrentStartDayTime(), dayBean.getCurrentDayEndTime(), offset, limit, new ITuyaResultCallback<List<TimeRangeBean>>() {
    @Override
    public void onSuccess(List<TimeRangeBean> result) {

    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

The screenshots of cloud storage events are encrypted before they can be displayed by the image encryption component. For more information, see Encrypted Images.

(Deprecated) Subscribe to cloud storage

This API method is no longer maintained. You can integrate with Cloud Storage UI BizBundle to implement the subscription.

API description

public void buyCloudStorage(Context mContext, DeviceBean deviceBean, String homeId, ICloudManagerCallback callback) {
        CameraCloudManager.getInstance().getCloudStorageUrl(mContext, deviceBean, homeId);
    }

Parameters

Parameter Description
mContext The context.
deviceBean The information about the device.
homeId The home ID.
callback The callback.

Example

cameraCloudSDK.buyCloudStorage(CameraCloudStorageActivity.this,
                               TuyaHomeSdk.getDataInstance().getDeviceBean(devId),
                               String.valueOf(FamilyManager.getInstance().getCurrentHomeId()), new ICloudManagerCallback() {
                                 @Override
                                 public void onError(int i) {

                                 }

                                 @Override
                                 public void onSuccess(Object o) {
                                   String uri = (String) o;
                                   Intent intent = new Intent(CameraCloudStorageActivity.this, WebViewActivity.class);
                                   intent.putExtra("Uri",uri);
                                   startActivity(intent);
                                 }
                               });

Error codes

Error code Description
10100 Failed to get the data of SECRET.
10101 Failed to get the data of AUTH.
10110 Other errors have occurred while processing your request.
10010 Failed to get the authentication information.
10011 Failed to get the video clip (authentication information) on the specified date.

Cloud storage management

Initialize an object

Creates a device object.

API description

void createCloudDevice(String cachePath, String devId)

Parameters

Parameter Description
cachePath The path through which video data is cached.
devId The device ID.

Example

cloudCamera.createCloudDevice(cachePath, devId);

Deinitialize the object

API description

void deinitCloudCamera();

Example

cloudCamera.deinitCloudCamera();

Destroy the object

API description

public void onDestroy();

Example

cloudCamera.onDestroy();

Register a cloud storage listener

Registers a listener with ITYCloudCamera. Otherwise, video images cannot be displayed as expected.

API description

void registerP2PCameraListener(AbsP2pCameraListener listener);

Parameters

Parameter Description
listener The callback that is executed when a P2P smart camera listener is registered.

Example

cloudCamera.registerP2PCameraListener(new AbsP2pCameraListener() {
    @Override
    public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
        super.onSessionStatusChanged(camera, sessionId, sessionStatus);
    }
});

Unregister a cloud storage listener

API description

void removeOnP2PCameraListener();

Example

cloudCamera.removeOnP2PCameraListener();

Bind a playback component view

API description

void generateCloudCameraView(IRegistorIOTCListener view);

Parameters

Parameter Description
view The player component.

Example

cloudCamera.generateCloudCameraView(mVideoView);

Cloud storage usage

Start playback

API description

void playCloudDataWithStartTime(long mStartTime, long mEndTime, boolean isEvent, OperationCallBack callback, OperationCallBack playFinishedCallBack);

Parameters

Parameter Description
mStartTime The 10-digit start timestamp.
mEndTime The 10-digit end timestamp of the period in which video clips are played back. By default, it is the end timestamp of the current date.
isEvent Indicates whether motion detection video clips are played back. Default value: false.
callBack The playback callback.
playFinishedCallBack The callback that is used when playback is ended.

Example

cloudCamera.playCloudDataWithStartTime(startTime, endTime, isEvent,
                                       new OperationCallBack() {
                                         @Override
                                         public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                                           // The callback that is executed when video clips are being played back. `playing` is returned.
                                         }

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

                                         }
                                       }, new OperationCallBack() {
                                         @Override
                                         public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                                           // The callback that is executed when playback is ended. `playCompleted` is returned.
                                         }

                                         @Override
                                         public void onFailure(int sessionId, int requestId, int errCode, Object camera) {
                                         }
                                       });

Pause playback

API description

int pausePlayCloudVideo(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.pausePlayCloudVideo(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
  }

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

  }
});

Resume playback

API description

int resumePlayCloudVideo(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.resumePlayCloudVideo(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
  }

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

  }
});

Stop playback

API description

int stopPlayCloudVideo(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.stopPlayCloudVideo(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
  }

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

  }
});

Download cloud-stored video clips

API description

void startCloudDataDownload(long startTime, long stopTime, String folderPath, String mp4FileName,
                                OperationCallBack callback, ProgressCallBack progressCallBack, OperationCallBack finishedCallBack);

Parameters

Parameter Description
startTime The 10-digit start timestamp of the period in which video clips are downloaded.
stopTime The 10-digit end timestamp of the period in which video clips are downloaded.
folderPath The path through which the video clips are stored.
mp4FileName The name of the target video file.
callback The callback.
progressCallBack The callback for the download progress.
finishedCallBack The callback that is executed when download is ended.

Stop video downloading

API description

void stopCloudDataDownload(OperationCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Delete cloud-stored video clips

API description

void deleteCloudVideo(long timeGT, long timeLT, String timeZone, final ITuyaResultCallback<String> listener);

Parameters

Parameter Description
timeGT The 10-digit start timestamp.
timeLT The end time.
timeZone The time zone.
listener The callback.

Video recording

Start video recording

API description

int startRecordLocalMp4(String folderPath, String fileName, OperationDelegateCallBack callBack);

Parameters

Parameter Description
folderPath The directory in which the video file is stored.
fileName The name of the video file.
callBack The callback.

Example

cloudCamera.startRecordLocalMp4(IPCCameraUtils.recordPath(devId), String.valueOf(System.currentTimeMillis()), new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    Toast.makeText(CameraCloudStorageActivity.this, "record start success", Toast.LENGTH_SHORT).show();
  }

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

Stop video recording

API description

int stopRecordLocalMp4(OperationDelegateCallBack callBack);

Parameters

Parameter Description
callBack The callback.

Example

cloudCamera.stopRecordLocalMp4(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    Toast.makeText(CameraCloudStorageActivity.this, "record end success", Toast.LENGTH_SHORT).show();
  }

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

Additional features

Cloud-stored video playback supports additional features, such as the audio switch and screenshots.

Get mute status

API description

int getCloudMute();

Example

cloudCamera.getCloudMute()

Set mute status

API description

void setCloudMute(final int mute, OperationDelegateCallBack callBack);

Parameters

Parameter Description
mute Specifies whether to mute the video. Valid values:
  • 1: yes
  • 0: no
callBack The callback.

Example

cloudCamera.setCloudMute(mute, new OperationDelegateCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data) {
                soundState = Integer.valueOf(data);
            }

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

Video screenshots

API description

int snapshot(String absoluteFilePath, OperationDelegateCallBack callBack);

Parameters

Parameter Description
absoluteFilePath The URL of the screenshot file.
callBack The callback.

Example

cloudCamera.snapshot(IPCCameraUtils.recordSnapshotPath(devId), new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    Toast.makeText(CameraCloudStorageActivity.this, "snapshot success", Toast.LENGTH_SHORT).show();
  }

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