菜单

17 视频-双路RTSP流切换(双路显示->第1路显示->第2路显示)

下载

1.三个控件(两个视频播放器,一个透明功能键)

2.分别设置控件属性

2.1 第1路【视频播放器】的属性

2.2 第2路【视频播放器】的属性

2.3 透明【功能键】属性

把边框设为0,透明度设为0,标题为空

3. 代码

主要是onLoad和功能键的点击事件代码

#include "Frm01.h"
 
Frm01::Frm01(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
hmiApp = app;
}
 
Frm01::~Frm01() {
}
 
void Frm01::onInit(){
}
 
void Frm01::createParts() {
setMainArg(0, 0, 1024, 600);
setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);
 
/*----------------------------- Video : wMVideo1                     -----------------------------*/
wMVideo1 = new STTFFmpeg(p_rt, this, "wMVideo1");
wMVideo1->channel = 0;
wMVideo1->setRotate(0);
wMVideo1->setMainArg(0, 0, 512, 600, "rtsp://192.168.1.101:8554/stream1");
wMVideo1->setAutoRestart(true);
wMVideo1->setVolume(50);
 
/*----------------------------- Video : wMVideo2                     -----------------------------*/
wMVideo2 = new STTFFmpeg(p_rt, this, "wMVideo2");
wMVideo2->channel = 1;
wMVideo2->setRotate(0);
wMVideo2->setMainArg(512, 0, 512, 600, "rtsp://192.168.1.101:8554/stream2");
wMVideo2->setAutoRestart(true);
wMVideo2->setVolume(50);
 
/*----------------------------- Button : wMButton1                   -----------------------------*/
wMButton1 = new STTButton(p_rt, this, "wMButton1", 0);
wMButton1->setMainArg(75, 21, 915, 554, false);
wMButton1->setPressedArg("", 0x0, "文泉驿微米黑", 16, 0);
wMButton1->setPressedStyle(8, 0, 0xebebeb, 0x999999, 1, 0, 0x999999, 1, 0xebebeb);
wMButton1->setReleasedArg("", 0x0, "文泉驿微米黑", 16, 0);
wMButton1->setReleasedStyle(5, 0, 0xebebeb, 0x999999, 1, 0, 0x999999, 1, 0xebebeb);
wMButton1->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMButton1_clk_cb);
 
/*called after widget created.*/
 
return; //createParts END
}
 
void Frm01::onLoad(){
wMVideo1->setVolume(5);//声音设小一点
wMVideo1->play(1000);//不要自动启动,在onLoad里延时启动
wMVideo2->play(2000);//不要自动启动,在onLoad里延时启动
}
 
bool Frm01::onClosing(){
return true;
}
 
void Frm01::onDispose(){
}
 
//控制状态
static int i = 0;
 
void Frm01::wMButton1_clk_cb(uint16_t code, LvEvent e) {
/*wMButton1()的点击事件*/
if(i == 0) {
//显示第1路视频:两个控件的地址都设为第1路视频地址
wMVideo1->setMainArg(0, 0, 1024, 600, "rtsp://192.168.1.101:8554/stream1");
wMVideo2->setMainArg(0, 0, 1024, 600, "rtsp://192.168.1.101:8554/stream1");
wMVideo1->play(1);//重新play一下,会刷新播放窗口大小
} else if(i == 1) {
//显示第2路视频:两个控件的地址都设为第2路视频地址
wMVideo1->setMainArg(0, 0, 1024, 600, "rtsp://192.168.1.101:8554/stream2");
wMVideo2->setMainArg(0, 0, 1024, 600, "rtsp://192.168.1.101:8554/stream2");
wMVideo1->play(1);//重新play一下,会刷新播放窗口大小
} else if(i == 2) {
//同时显示2路视频:两个控件的地址都设为第2路视频地址
wMVideo1->setMainArg(0, 0, 512, 600, "rtsp://192.168.1.101:8554/stream1");
wMVideo2->setMainArg(512, 0, 512, 600, "rtsp://192.168.1.101:8554/stream2");
wMVideo1->play(1);//重新play一下,会刷新播放窗口大小
wMVideo2->play(2000);//重新play一下,会刷新播放窗口大小
}
i++;
i %= 3;
}

工程源码下载

最近修改: 2026-08-11Powered by