文档

直播播放器

更新时间:
一键部署

本文介绍PC应用端,直播播放器的使用流程。

使用流程

  1. 创建直播播放器。

  2. 配置播放器的渲染窗口并设置播放器回调。

  3. 按需配置播放器的其他参数。例如:软硬解码偏好、视频画面模式等。

  4. 调用QueryLiveStreaming接口获取IPC设备的直播开播地址,并作为数据源设置给播放器。

  5. 开始播放。

  6. 停止播放。

  7. 销毁直播播放器。

使用示例

// 创建并显示播放窗口
QPoint playerViewPos = ui->playerviewplaceholder->pos();
QSize playerViewSize = ui->playerviewplaceholder->size();
pLVGLWidget_ = new LVGLWidget(0, this);
pLVGLWidget_->resize(playerViewSize);
pLVGLWidget_->move(playerViewPos);
pLVGLWidget_->show();

// 创建并设置播放器
pLVLivePlayer_ = createLVLivePlayer();
pLVLivePlayer_->setWindow(pLVGLWidget_);
pLVLivePlayer_->setPlayerCallback(this, nullptr);

...
// 处理播放器回调
void LivePlayerWindow::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 LivePlayerWindow::onPlayerStateChange(LVPlayerState state, void *pUserData) {
    emit appendLog(QString::asprintf("player state changed to %d", state));
}

void LivePlayerWindow::onRenderedFirstFrame(int elapsedTimeInMs, void *pUserData) {
    emit appendLog(QString::asprintf("首帧出图耗时: %d ms", elapsedTimeInMs));
}

void LivePlayerWindow::onVideoSizeChanged(int width, int height, void *pUserData) {
    emit appendLog(QString::asprintf("视频宽高变化:w=%d h=%d", width, height));
}

void LivePlayerWindow::onStandardSeiInfoUpdate(const uint8_t *buffer, int length, long timeStamp, void *pUserData) {
   emit appendLog(QString::asprintf("收到sei帧长度%d", length));
}

...
// 设置数据源,rtmp地址从云服务获取
pLVLivePlayer_->setDataSource("rtmp://xx.xx.xx.xx/live/xxx", true, decryptIvBase64String, decryptKeyBase64String);

// 设置解码策略为硬解码优先
pLVLivePlayer_->setDecoderStrategy(LV_DECODER_STRATEGY_HARDWARE_FIRST);
// 设置画面模式为保持宽高
pLVLivePlayer_->setVideoScalingMode(LV_MEDIA_VIDEO_SCALING_MODE_FIT);
// 设置播放停止时画面保留最后一帧
pLVLivePlayer_->setPlayerStoppedDrawingMode(LV_PLAYER_STOPPED_DRAWING_MODE_ALWAYS_KEEP_LAST_FRAME);
...
// 开始播放
LVPlayerCode code = pLVLivePlayer_->start();
if (code == LV_PLAYER_SUCCESS) {
    emit appendLog("开始播放成功");
} else {
    emit appendLog("开始播放失败");
}
...
// 停止播放
LVPlayerCode code = pLVLivePlayer_->stop();
if (code == LV_PLAYER_SUCCESS) {
    emit appendLog("停止播放成功");
} else {
    emit appendLog("停止播放失败");
}
...
// 销毁播放器
destroyLVLivePlayer(&pLVLivePlayer_);
delete pLVGLWidget_;

  • 本页导读 (1)
文档反馈