Video Alerts

Last Updated on : 2024-06-17 08:02:29download

ThingCloudVideoPlayer is the entity object of the video alert player container and provides API methods that deal with videos related to alerts.

Process

Video Alerts

Create a video player

API description

Creates an entity object of the video alert player container.

IThingCloudVideo createVideoMessagePlayer();

Example

private IThingCloudVideo mCloudVideo;

IThingIPCMsg message = ThingIPCSdk.getMessage();
if (message != null) {
    mCloudVideo = message.createVideoMessagePlayer();
}

Register a listener

API description

Registers a listener. The callback for video playback can be executed only after the listener is registered.

void registerP2PCameraListener(AbsP2pCameraListener listener);

Parameters

Parameter Description
AbsP2pCameraListener The callback that is executed after videos are played back.

Example

private IThingCloudVideo mCloudVideo;

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

Bind a player

API description

Injects a player view to render video images.

void generateCloudCameraView(IRegistorIOTCListener view);

Parameters

Parameter Description
IRegistorIOTCListener The player component.

Create cloud-stored video playback object

API description

Creates a cloud-stored video player.

void createCloudDevice(String cachePath, String devId, OperationDelegateCallBack callBack);

Parameters

Parameter Description
cachePath The URL of the cached file.
devId The device ID.
OperationDelegateCallBack The callback.

Example

cloudVideo.createVideoMessagePlayer().createCloudDevice(cachePath, devId, new OperationDelegateCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data) {
            }

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

Play back cloud-stored video footage

API description

Plays back cloud-stored video footage attached to an alert.

void playVideo(String videoUrl, int startTime, String encryptKey, OperationCallBack callback, OperationCallBack playFinishedCallBack);

Parameters

Parameter Description
videoUrl The URL of the video footage.
startTime The time from which video footage playback is started. Default value: 0.
encryptKey The key used to decrypt video footage for playback.
callback The callback that is executed when playback is started.
playFinishedCallBack The callback that is executed when playback is finished.

Example

public void playVideo(String videoUrl, int startTime, String encryptKey) {
        if (cloudVideo == null) {
            return;
        }
        cloudVideo.playVideo(videoUrl, startTime, encryptKey, new OperationCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                playState = CloudPlayState.STATE_PLAYING;
            }

            @Override
            public void onFailure(int sessionId, int requestId, int errCode, Object camera) {
                playState = CloudPlayState.STATE_ERROR;
            }
        }, new OperationCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                playState = CloudPlayState.STATE_COMPLETED;
                cloudVideo.audioClose();
            }

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

Pause playback

API description

void pauseVideo(OperationCallBack callback);

Parameters

Parameter Description
OperationDelegateCallBack The callback.

Example

public void pauseVideo() {
        if (cloudVideo == null) {
            return;
        }
        cloudVideo.pauseVideo(new OperationCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                playState = CloudPlayState.STATE_PAUSED;
            }

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

Resume playback

API description

void resumeVideo(OperationCallBack callback);

Parameters

Parameter Description
OperationDelegateCallBack The callback.

Example

public void  resumeVideo() {
        if (cloudVideo == null) {
            return;
        }
        cloudVideo.resumeVideo(new OperationCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                playState = CloudPlayState.STATE_PLAYING;
            }

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

Stop playback

API description

void stopVideo(OperationCallBack callback);

Parameters

Parameter Description
OperationDelegateCallBack The callback.

Example

public void stopVideo() {
        if (cloudVideo == null) {
            return ;
        }
        cloudVideo.stopVideo(new OperationCallBack() {
            @Override
            public void onSuccess(int sessionId, int requestId, String data, Object camera) {
                playState = CloudPlayState.STATE_STOP;
            }

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

Set pickup mode

API description

Enables or disables the audio channel.

void setCloudVideoMute(int mute, OperationDelegateCallBack callBack);

Parameters

Parameter Description
mute The pickup mode. Valid values:
  • ICameraP2P.MUTE: mute
  • ICameraP2P.UNMUTE: unmuted
OperationDelegateCallBack The callback.

Example

private void setCloudVideoMute(int voiceMode) {
        if (cloudVideo == null) {
            return ;
        }
        cloudVideo.setCloudVideoMute(voiceMode,  new  OperationDelegateCallBack() {

            @Override
            public void onSuccess(int sessionId, int requestId, String data) {
            }

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

Destroy cloud-stored video player object

API description

Destroys the cloud-stored video player if cloud-stored video footage is not used.

void deinitCloudVideo();

Callback for video frames

API description

public void onReceiveFrameYUVData(int sessionId, ByteBuffer y, ByteBuffer u, ByteBuffer v, int width, int height, int nFrameRate, int nIsKeyFrame, long timestamp, long nProgress, long nDuration, Object camera);

Parameters

Parameter Description
sessionId The session ID.
Y The luma (Y’) information of video streams.
u The chroma (U) channel information of video streams.
v The chroma (V) channel information of video streams.
width The width of video images.
height The height of video images.
nFrameRate The frame rate of video streams.
nIsKeyFrame Indicates whether a keyframe or an I-frame is used.
timestamp The timestamp.
nProgress The playback progress of the video pushed by the Message Center module.
nDuration The duration of the video pushed by the Message Center module.
camera The IPC that collects video footage.

Only nProgress and nDuration are required for video playback.

Example

public void onReceiveFrameYUVData(int sessionId, ByteBuffer y, ByteBuffer u, ByteBuffer v, int width, int height, int nFrameRate, int nIsKeyFrame, long timestamp, long nProgress, long nDuration, Object camera) {
        Map map = new HashMap<String, Long>(2);
        map.put("progress", nProgress);
        map.put("duration", nDuration);
        mHandler.sendMessage(MessageUtil.getMessage(ICameraVideoPlayModel.MSG_CLOUD_VIDEO_INFO, ICameraVideoPlayModel.OPERATE_SUCCESS, map));
}

Navigate from alerts to SD card-stored content

By default, alerts are generated independently from playback of SD card-stored content. In certain conditions, video recording and alert triggering might occur at the same time.

  • During SD card-stored video recording, alerts and video footage can be simultaneously generated by the same triggers. Specifically, they have the following differences:

    • Alerts are stored in the cloud.
    • SD card-stored video footage is stored on an IPC. If the SD card capacity is insufficient, the earlier video footage might be overwritten by later footage.
  • The switch for SD card-stored video recording is set independently from the switch for detection alerts. Therefore, during SD card-stored video recording, alerts do not always trigger video recording.

    In certain cases, alerts can be linked with video footage stored on the SD card. The IPC SDK does not provide a typical API method to query video footage based on this type of correlation. However, to find the video footage triggered by alerts, users can find the time and date when the alerts were generated. Then, check whether the target video footage was created on this date. You can implement navigation from alerts to SD card-stored video footage in this way.