Feature Usage
Updated: 2026-08-14 14:36:53
This document provides operational steps and code examples for using the C++ SDK. Through this document, you can quickly understand how to utilize the features provided by the SDK. You can also learn and develop your own business using the examples in the Demo.
SDK Terminology and Feature Description
- See
plv-player-def.h
SDK Global Functions
- Set logs and log filtering items.
- Set audience information (for backend data tracking).
- Set related parameters (hardware decoding switch, network request type, etc.).
- Initialize (userid, key).
- Exit and destruct.
std::count << "the sdk version:" << PLVGetSdkVersion() << std::endl;
// 设置日志信息,路径须使用utf8
PLVSetSdkLogMessageCallback(true,[](LOG_FILTER_TYPE, const char*, void*){}, nullptr);
PLVSetSdkLogLevel(LOG_FILTER_INFO);
int ret = PLVSetSdkLogFile("C:/log/sdk.log");
std::count << "the log file result:" << ret << std::endl;
// 设置观看者viewer信息,适用于点播与直播.用于定位播放质量问题,在线播放下可以通过后台来查看,建议调用此接口设置信息
// 最新 vrm12/vrm13 下必须设置,否则播放会报错
std::string viewerId = "业务id";// 唯一值
std::string viewerName = "业务nick";
std::string viewerAvatar= "业务Avatar";
PLVSetSdkViewerInfo(viewerId.c_str(), viewerName.c_str(), viewerAvatar.c_str());
//初始化SDK,建议不要传入secretKey与appSecret,相关信息由业务服务器获取后传给客户端
PLVAccountInfo accountInfo;
accountInfo.userId = "xxxx";
ret = PLVInitSdkLibrary(&accountInfo);
std::cout << "init sdk result:" << ret << std::endl;
//以下为点直播播放相关全局设置,详见文档信息
PLVSetSdkLocalRememberPlay(true);
PLVSetSdkKeepLastFrame(true);
PLVSetSdkHwdecEnable(false);
PLVSetSdkVideoOutputDevice(VIDEO_OUTPUT_GPU, nullptr);
PLVSetSdkSeed("xxxxxxx"); // 仅针对点播vrm12/vrm13在线播放有效
//以下为下载相关全局设置,详见文档信息
PLVSetSdkRetryAttempts();
//结束后释放SDK
PLVReleaseSdkLibrary();
SDK Anti-Recording and Virtual Machine Detection
Description of the anti-recording feature. It can only be used after SDK initialization. The operational steps and feature examples are as follows:
// 注意通知回调都是子线程,如果更新 ui 及操作 api 都需要 post 到主线程
// 启用软件防录制,并进行软件防录制检测
PLVSetPreventSoftwareRecording((void*)App()->GetMainWindow()->winId(), true);
PLVSetDetectSoftwareRecordingHandler(true,
[](SOFTWARE_RECORDING_NOTIFY_TYPE type, const char* softwares, void* data){
// 有插件注入通知,可能有软件在录制你的播放界面,可以在业务上做处理
// PostMessage
}, userdata);
// 启用硬件防录制检测
PLVSetDetectHardwareRecordingHandler(true,
[](DEVICE_CHANGED_TYPE type, const char* device, void* data){
// HDMI 设备有变动,请根据 type 类型判断,可能是 HDMI 设备在录制你的屏幕
// PostMessage
}, userdata);
// 虚拟机检测, check vmFlags
int vmFlags = PLVDetectVM();
SDK VOD Downloader
The operational steps and feature examples for video downloading are as follows:
// 注意通知回调都是子线程,如果更新 ui 及操作 api 都需要 post 到主线程
// 创建下载器
PLVDownloadPtr downloader = PLVDownloadCreate();
// 设置错误回调通知
PLVDownloadSetErrorHandler(downolader, [](const char* vid, int code, void* data) {
// 错误通知 code 为错误码
// PostMessage
}, userdata);
// 设置下载进度回调通知
PLVDownloadSetProgressHandler(downolader, [](const char* vid, long long receivedBytes, long long totalBytes, void* data) {
// 下载进度
// PostMessage
}, userdata);
// 设置下载结果回调通知
PLVDownloadSetResultHandler(downolader, [](const char* vid, int rate, int code, void* data) {
// 下载结果
// PostMessage
}, userdata);
// 设置下载信息,操作前必须先调用此接口
PLVDownloadSetInfo(downolader, vid, path, rate);
// 开始下载,autoDownRate 是否自动降清晰度,false 如果没有这个清晰度则返回错误码
PLVDownloadStart(downolader, token, autoDownRate);
// 暂停下载,不退出线程,可以快速切换下载状态
PLVDownloadPause(downolader);
// 结束下载,退出线程
PLVDownloadStop(downolader);
// 删除下载文件
PLVDownloadDelete(downolader);
// 销毁下载器
PLVDownloadDestroy(downolader);
SDK VOD Player
The operational steps and feature examples for VOD video playback are as follows:
// 注意通知回调都是子线程,如果更新 ui 及操作 api 都需要 post 到主线程
// 创建播放器
PLVPlayerPtr player = PLVPlayerCreate((void*)winId());
// 设置播放器的播放状态通知
PLVPlayerSetStateHandler(player, [](const char* vid, int state, void* data) {
// 播放器的状态,state 参见 PLAYER_MEDIA_STATE
// PostMessage();
}, userdata);
// 设置视频的属性回调通知
PLVPlayerSetPropertyHandler(player, [](const char* vid, int property, int format, const char* value, void* data) {
// 播放器的属性值
// PostMessage();
}, userdata);
// 设置码率清晰度变化通知 (只有输入的码率不存在,自动降值才会触发此通知)
PLVPlayerSetRateChangeHandler(player, [](const char* vid, int inputBitRate, int realBitRate, void* data) {
// 真实的清晰度,比如目标清晰度为超清,但不存在此清晰度,会自动降值为 realBitRate
// PostMessage();
}, userdata);
// 设置播放器播放进度回调通知
PLVPlayerSetProgressHandler(player, [](const char* vid, int millisecond, void* data) {
// 播放位置
// PostMessage();
}, userdata);
// 设置音频播放错误回调通知
PLVPlayerSetAudioPlayErrorHandler(player, [](const char* vid, void* data) {
// 音频播放错误
// PostMessage();
}, userdata);
// 设置跑马灯
PLVPlayerSetOSDConfig(player, true, config);
// 设置 LOGO text
PLVPlayerSetLogoText(player, true, config);
// 设置缓存,可以不设置,播放器会有默认值
PLVPlayerSetCacheConfig(player, true, maxCacheBytes, maxCacheSeconds);
// 播放前要先设置 vid
PLVPlayerSetInfo(player, vid, path, rate);
// 开始播放,token 外部获取
PLVPlayerPlay(player,token, seekMillisecond, autoDownRate);
// 暂停播放
PLVPlayerPause(player, pause);
// 静音
PLVPlayerSetMute(player, mute);
// 跳转,由于视频文件都是经过后台编码过,关键帧会被优化,跳转会不准确。可以对比 mp4 与 m3u8,差别会比较大,mp4 拖动很准,m3u8 跳动很大。
PLVPlayerSetSeek(player, millisecond);
// 跳转到结束,由于 m3u8 跳转不准,有需要跳转到尾部的请使用此接口
PLVPlayerSeekToEnd(player);
// 设置音量
PLVPlayerSetVolume(player, volume);
// 声音增益,最大可到 1000
PLVPlayerSetVolumeMax(player, volume);
// 截图, 注意使用UTF8
PLVPlayerScreenshot(player, filename);
// 变速播放
PLVPlayerSetSpeed(player, speed);
// 获取与设置播放设备
PLVPlayerGetCurrentAudioDevice(player, deviceId);
PLVPlayerSetCurrentAudioDevice(player, deviceId);
// 停止播放
PLVPlayerStop(player);
// 销毁播放器
PLVPlayerDestroy(player);
SDK Live Player
The operational steps and feature examples for live video playback are as follows:
// 注意通知回调都是子线程,如果更新 ui 及操作 api 都需要 post 到主线程
// 创建直播播放器
PLVLivePlayerPtr livePlayer = PLVLivePlayerCreate((void*)winId());
// 设置播放状态通知
PLVLivePlayerSetStateHandler(livePlayer, [](int state, void *data){
// 播放器的状态,state 参见 PLAYER_MEDIA_STATE
// PostMessage();
}, userdata);
// 设置视频的属性回调通知
PLVLivePlayerSetPropertyHandler(livePlayer, [](int property, int format, const char* value, void* data) {
// 播放器的属性值
// PostMessage();
}, userdata);
// 设置音频播放错误回调通知
PLVLivePlayerSetAudioPlayErrorHandler(livePlayer, [](void* data) {
// 音频播放错误
// PostMessage();
}, userdata);
// 设置直播频道状态回调通知
PLVLivePlayerSetChannelStateHandler(livePlayer, [](int state, void *data){
// 频道直播状态, 参见 LIVE_PLAYER_CHANNEL_STATE
// PostMessage();
}, userdata);
// 设置直播频道信息回调通知
PLVLivePlayerSetChannelInfoHandler(livePlayer, [](const PLVChannelInfo *info, void *data){
// 频道信息
// PostMessage();
},userdata);
// 设置跑马灯
PLVLivePlayerSetOSDConfig(livePlayer, true, config);
// 设置 LOGO text
PLVLivePlayerSetLogoText(livePlayer, true, config);
// 设置播放缓存,可以不设置
PLVLivePlayerSetCacheConfig(livePlayer, cacheMs, speedTrackingEnable, seekTrackingEnable);
// 开始播放, 如果频道未直播,播放器会一直轮询,直到直播后自动开启播放
PLVLivePlayerPlay(livePlayer, channelId);
// 切换线路
PLVLivePlayerSetLine(livePlayer, index);
// 切换清晰度
PLVLivePlayerSetQuality(livePlayer, index);
// 切换播放模式
PLVLivePlayerSetPlayMode(livePlayer, mode);
// 暂停直播
PLVLivePlayerPause(livePlayer, pause);
// 静音
PLVLivePlayerMute(livePlayer, mute);
// 设置音量
PLVLivePlayerSetVolume(livePlayer, volume);
// 声音增益,最大可到 1000
PLVLivePlayerSetVolumeMax(livePlayer, volume);
// 截图, 注意使用UTF8
PLVLivePlayerScreenshot(livePlayer, filename);
// 获取与设置播放设备
PLVLivePlayerGetCurrentAudioDevice(livePlayer, deviceId);
PLVLivePlayerSetCurrentAudioDevice(livePlayer, deviceId);
// 停止直播播放
PLVLivePlayerStop(livePlayer);
// 销毁直播播放器
PLVLivePlayerDestroy(livePlayer);
SDK Notes
- All interfaces related to paths must use UTF-8 encoding.
- For all callback notifications, you cannot update the UI or call other APIs within them. You must post them to the UI thread.
