This topic describes how to use a video-on-demand (VOD) player in a PC app.
Procedure
Create a VOD player.
Configure a rendering view and callbacks for the player.
Configure other parameters for the player based on your business requirements, such as the decoding policy and display mode.
Specify a playback source.
Play device recordings by file name: Call the QueryDeviceVodUrl operation to obtain the Real-Time Messaging Protocol (RTMP) playback URL of a recording of a specified name in the storage card of an on-premises network video recorder (NVR) or an IP camera. Then, specify the RTMP playback URL as a playback source for the player.
Play device recordings by time: Call the QueryDeviceVodUrlByTime operation to obtain the RTMP playback URL of one or more recordings whose modification time is within a specified time range in the storage card of an on-premises NVR or an IP camera. Then, specify the RTMP playback URL as a playback source for the player.
Play cloud recordings by file name: Call the QueryRecordUrl operation to obtain the HTTP Live Streaming (HLS) playback URL of a cloud recording of a specified name. Then, specify the RTMP playback URL as a playback source for the player.
Start the playback.
Pause or resume the playback, and seek to a point in time of the playback.
Stop the playback.
Delete the VOD player.
Sample code
Play device recordings on demand
// Create and display the playback view.
QPoint playerViewPos = ui->playerviewplaceholder->pos();
QSize playerViewSize = ui->playerviewplaceholder->size();
pLVGLWidget_ = new LVGLWidget(0, this);
pLVGLWidget_->resize(playerViewSize);
pLVGLWidget_->move(playerViewPos);
pLVGLWidget_->show();
// Create and configure a player.
pLVVodPlayer_ = createLVVodPlayer();
pLVVodPlayer_->setWindow(pLVGLWidget_);
pLVVodPlayer_->setPlayerCallback(this, nullptr);
...
// Configure the callbacks for the player.
void VodPlayerWindow::onError(const LVPlayerError &error, void *pUserData) {
emit appendLog(QString::asprintf("player error: code=%d subCode=%d message=%s", error.code, error.subCode,
error.message.c_str()));
}
void VodPlayerWindow::onPlayerStateChange(LVPlayerState state, void *pUserData) {
emit appendLog(QString::asprintf("player state changed to %d", state));
}
void VodPlayerWindow::onRenderedFirstFrame(int elapsedTimeInMs, void *pUserData) {
emit appendLog(QString::asprintf("Time to first frame: %d ms", elapsedTimeInMs));
}
void VodPlayerWindow::onVideoSizeChanged(int width, int height, void *pUserData) {
emit appendLog(QString::asprintf("Changes in the width or height of a video: w=%d h=%d", width, height));
}
void VodPlayerWindow::onVodCompletion(void *pUserData) {
emit appendLog("The playback ended");
}
void VodPlayerWindow::onStandardSeiInfoUpdate(const uint8_t *buffer, int length, long timeStamp, void *pUserData) {
emit appendLog(QString::asprintf("Received SEI frame length%d", length));
}
...
// Specify an RTMP URL as the data source. The URL is obtained from IoT Platform.
pLVVodPlayer_->setDataSource("rtmp://xx.xx.xx.xx/vod/xxx", true, decryptIvBase64String, decryptKeyBase64String);
// Specify hardware decoding as the highest-priority decoding policy.
pLVVodPlayer_->setDecoderStrategy(LV_DECODER_STRATEGY_HARDWARE_FIRST);
// Specify an aspect ratio-based display mode.
pLVVodPlayer_->setVideoScalingMode(LV_MEDIA_VIDEO_SCALING_MODE_FIT);
// Specify that the player displays the last frame when the playback stops.
pLVVodPlayer_->setPlayerStoppedDrawingMode(LV_PLAYER_STOPPED_DRAWING_MODE_ALWAYS_KEEP_LAST_FRAME);
...
// Start the playback.
LVPlayerCode code = pLVVodPlayer_->start();
if (code == LV_PLAYER_SUCCESS) {
emit appendLog("The playback started successfully");
} else {
emit appendLog("The playback failed to start");
}
...
// Pause the playback.
pLVVodPlayer_->pause();
...
// Resume the playback.
pLVVodPlayer_->resume();
...
// Stop the playback.
LVPlayerCode code = pLVVodPlayer_->stop();
if (code == LV_PLAYER_SUCCESS) {
emit appendLog("The playback stopped successfully");
} else {
emit appendLog("The playback failed to be stopped");
}
...
// Delete the player.
destroyLVVodPlayer(&pLVVodPlayer_);
delete pLVGLWidget_;Play cloud recordings on demand
// Create and display a playback view.
QPoint playerViewPos = ui->playerviewplaceholder->pos();
QSize playerViewSize = ui->playerviewplaceholder->size();
pLVGLWidget_ = new LVGLWidget(0, this);
pLVGLWidget_->resize(playerViewSize);
pLVGLWidget_->move(playerViewPos);
pLVGLWidget_->show();
// Create and configure a player.
pLVVodPlayer_ = createLVVodPlayer();
pLVVodPlayer_->setWindow(pLVGLWidget_);
pLVVodPlayer_->setPlayerCallback(this, nullptr);
...
// Configure the callbacks for the player.
void VodPlayerWindow::onError(const LVPlayerError &error, void *pUserData) {
emit appendLog(QString::asprintf("player error: code=%d subCode=%d message=%s", error.code, error.subCode,
error.message.c_str()));
}
void VodPlayerWindow::onPlayerStateChange(LVPlayerState state, void *pUserData) {
emit appendLog(QString::asprintf("player state changed to %d", state));
}
void VodPlayerWindow::onRenderedFirstFrame(int elapsedTimeInMs, void *pUserData) {
emit appendLog(QString::asprintf("Time to first frame: %d ms", elapsedTimeInMs));
}
void VodPlayerWindow::onVideoSizeChanged(int width, int height, void *pUserData) {
emit appendLog(QString::asprintf("Changes in the width or height of a video: w=%d h=%d", width, height));
}
void VodPlayerWindow::onVodCompletion(void *pUserData) {
emit appendLog("The playback ended");
}
void VodPlayerWindow::onStandardSeiInfoUpdate(const uint8_t *buffer, int length, long timeStamp, void *pUserData) {
emit appendLog(QString::asprintf("Received SEI frame length%d", length));
}
...
// Specify an RTMP URL as the data source. The URL is obtained from IoT Platform.
pLVVodPlayer_->setDataSource("https://xx.xx.xx.xx/hls/xxx.m3u8");
// Specify hardware decoding as the highest-priority decoding policy.
pLVVodPlayer_->setDecoderStrategy(LV_DECODER_STRATEGY_HARDWARE_FIRST);
// Specify an aspect ratio-based display mode.
pLVVodPlayer_->setVideoScalingMode(LV_MEDIA_VIDEO_SCALING_MODE_FIT);
// Specify that the player displays the last frame when the playback stops.
pLVVodPlayer_->setPlayerStoppedDrawingMode(LV_PLAYER_STOPPED_DRAWING_MODE_ALWAYS_KEEP_LAST_FRAME);
...
// Start the playback.
LVPlayerCode code = pLVVodPlayer_->start();
if (code == LV_PLAYER_SUCCESS) {
emit appendLog("The playback started successfully");
} else {
emit appendLog("The playback failed to start");
}
...
// Pause the playback.
pLVVodPlayer_->pause();
...
// Resume the playback.
pLVVodPlayer_->resume();
...
// Stop the playback.
LVPlayerCode code = pLVVodPlayer_->stop();
if (code == LV_PLAYER_SUCCESS) {
emit appendLog("The playback stopped successfully");
} else {
emit appendLog("The playback failed to be stopped");
}
...
// Delete the player.
destroyLVVodPlayer(&pLVVodPlayer_);
delete pLVGLWidget_;