菜单

模仿VLC的mp4视频播放器

下载

一、概述

mp4文件播放器

二、主要功能

1.模仿VLC播放器界面
2.mp3播放
3.多路(2路/3路/4路)流媒体播放
4.视频上叠加文字去锯齿

三、源码导入

使用说明

1.导入项目

源码下载STTvlc.zip
https://gitee.com/clawclaw/sttvlc/repository/archive/master.zip
运行前,将mp4文件复制到项目的【资源/视频】目录下

2.运行界面


下侧按钮功能分别为:
播放/暂停
上一首
停止
下一首
全屏/还原
高级功能(无)
播放清单
不循环/全部循环/单曲循环
顺序播放/随机播放

3.播放清单

点击【播放】或【播放清单】按钮

点击【刷新播放列表】
*清单不选中时,默认播放第一首
*如果是全部循环,则会循环播放清单中所有视频

4.其他操作略

5.主要源码

language 复制代码
#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);

	/*----------------------------- Panel : wMPanel3                     -----------------------------*/
	wMPanel3 = new STTPanel(p_rt, this, "wMPanel3");
	wMPanel3->setMainArg(0, 0, 1024, 24, 0);
	wMPanel3->setMainStyle(0, 0x80ff, 0xffffff, GradDir::HOR, 255, 1, 0xc0c0c0);

	/*----------------------------- Image : wMImage1                     -----------------------------*/
	wMImage1 = new STTImage(p_rt, wMPanel3, "wMImage1");
	wMImage1->setMainArg(1, 1, 22, 22);
	wMImage1->addStateImg("0", "./images/img17448068950030_22X22R0.jpg");

	/*----------------------------- Label : wMLabel6                     -----------------------------*/
	wMLabel6 = new STTLabel(p_rt, wMPanel3, "wMLabel6");
	wMLabel6->setMainArg(41, 0, 245, 24, "鑫通态VLC media player", TextAlign::LEFT, LabelLongMode::CLIP, 30);
	wMLabel6->setFonts(0x0, 16, "文泉驿微米黑", 0);
	wMLabel6->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel6->setFormatText(TextAlign::LEFT, LabelLongMode::CLIP, 30);

	/*----------------------------- TileView : wMTileView2               -----------------------------*/
	wMTileView2 = new STTTileView(p_rt, this, "wMTileView2", 2, 1);
	wMTileView2->setMainArg(0, 24, 1024, 488);
	wMTileView2->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- TileView : wMTileView2Tile1          -----------------------------*/
	STTTile *wMTileView2Tile1 = wMTileView2->getTile(0);

	/*----------------------------- Panel : wMPanel4                     -----------------------------*/
	wMPanel4 = new STTPanel(p_rt, wMTileView2Tile1, "wMPanel4");
	wMPanel4->setMainArg(0, 0, 1024, 488, 0);
	wMPanel4->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- Video : wMVideo2                     -----------------------------*/
	wMVideo2 = new STTFFmpeg(p_rt, wMPanel4, "wMVideo2");
	wMVideo2->channel = 0;
	wMVideo2->setRotate(0);
	wMVideo2->setMainArg(0, 0, 1024, 488, "");
	wMVideo2->bindData(_V("播放时长秒"));

	/*----------------------------- TileView : wMTileView2Tile2          -----------------------------*/
	STTTile *wMTileView2Tile2 = wMTileView2->getTile(1);

	/*----------------------------- Panel : wMPanel5                     -----------------------------*/
	wMPanel5 = new STTPanel(p_rt, wMTileView2Tile2, "wMPanel5");
	wMPanel5->setMainArg(0, 0, 1024, 488, 0);
	wMPanel5->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- List : wMList1                       -----------------------------*/
	wMList1 = new STTList(p_rt, wMPanel5, "媒体列表");
	wMList1->setMainArg(0, 0, 908, 488, false);
	wMList1->setFonts(0x0, 0xffffff, 16, "文泉驿微米黑", 0);
	wMList1->setMainStyle(10, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0);
	wMList1->setButtonStyleSelected(0, 0x1a2b1, 0xffffff, 0, 0);

	/*----------------------------- Button : wMButton1                   -----------------------------*/
	wMButton1 = new STTButton(p_rt, wMPanel5, "刷新媒体列表", 0);
	wMButton1->setMainArg(915, 69, 98, 48, false);
	wMButton1->setPressedArg("刷新媒体列表", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->setReleasedArg("刷新媒体列表", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMButton1_clk_cb);

	/*----------------------------- Button : wMButton4                   -----------------------------*/
	wMButton4 = new STTButton(p_rt, wMPanel5, "删除选中媒体", 0);
	wMButton4->setMainArg(915, 130, 98, 48, false);
	wMButton4->setPressedArg("删除选中媒体", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->setReleasedArg("删除选中媒体", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMButton4_clk_cb);

	/*----------------------------- Panel : wMPanel2                     -----------------------------*/
	wMPanel2 = new STTPanel(p_rt, this, "wMPanel2");
	wMPanel2->setMainArg(0, 519, 1023, 80, 0);
	wMPanel2->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 1, 0xc0c0c0);

	/*----------------------------- Label : wMLabel1                     -----------------------------*/
	wMLabel1 = new STTLabel(p_rt, wMPanel2, "已播放时间");
	wMLabel1->setMainArg(0, 0, 50, 16, "--:--", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel1->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel1->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel1->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- Label : wMLabel2                     -----------------------------*/
	wMLabel2 = new STTLabel(p_rt, wMPanel2, "总时长");
	wMLabel2->setMainArg(973, 0, 50, 16, "00:00", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel2->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel2->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel2->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- Slider : wMSlider1                   -----------------------------*/
	wMSlider1 = new STTSlider(p_rt, wMPanel2, "wMSlider1");
	wMSlider1->setMainArg(55, 2, 912, 12, 0, 0, 1, false);
	wMSlider1->setMainStyle(9999, 0xc0c0c0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, NULL);
	wMSlider1->setIndicStyle(9999, 0x80ff, 0xffffff, 0, 0, 0x80ff, 0, 0xffffff, NULL);
	wMSlider1->setKnobStyle(100, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, NULL, 0);
	wMSlider1->bindData(_V("播放时长秒"));
	wMSlider1->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm01::wMSlider1_vch_cb);

	/*----------------------------- MSwitch : wMMSwitch1                 -----------------------------*/
	wMMSwitch1 = new STTButton(p_rt, wMPanel2, "播放与暂停", 2);
	wMMSwitch1->setMainArg(3, 21, 40, 40, false);
	wMMSwitch1->setImg("1", "./images/img17448150555490_40X40R0.png", "");
	wMMSwitch1->setImg("0", "./images/img17448148045820_40X40R0.png", "");
	wMMSwitch1->bindData(_V("播放暂停"));
	wMMSwitch1->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch1_clk_cb);

	/*----------------------------- Label : wMLabel3                     -----------------------------*/
	wMLabel3 = new STTLabel(p_rt, wMPanel2, "wMLabel3");
	wMLabel3->setMainArg(0, 63, 872, 16, "文件路径", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel3->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel3->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 1, 0x0, 48);
	wMLabel3->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- Label : wMLabel4                     -----------------------------*/
	wMLabel4 = new STTLabel(p_rt, wMPanel2, "wMLabel4");
	wMLabel4->setMainArg(877, 63, 50, 16, "倍速", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel4->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel4->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 1, 0x0, 48);
	wMLabel4->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- Label : wMLabel5                     -----------------------------*/
	wMLabel5 = new STTLabel(p_rt, wMPanel2, "wMLabel5");
	wMLabel5->setMainArg(934, 63, 88, 16, "--:--/--:--", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel5->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel5->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 1, 0x0, 48);
	wMLabel5->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*----------------------------- MSwitch : wMMSwitch2                 -----------------------------*/
	wMMSwitch2 = new STTButton(p_rt, wMPanel2, "播放上一个", 2);
	wMMSwitch2->setMainArg(61, 22, 36, 36, false);
	wMMSwitch2->setImg("1", "./images/button_10-1_36X36.gray.svg", "");
	wMMSwitch2->setImg("0", "./images/img17449589357000_36X36R0.png", "");
	wMMSwitch2->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch2_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch3                 -----------------------------*/
	wMMSwitch3 = new STTButton(p_rt, wMPanel2, "停止播放", 2);
	wMMSwitch3->setMainArg(98, 22, 36, 36, false);
	wMMSwitch3->setImg("1", "./images/button_10-1_36X36.gray.svg", "");
	wMMSwitch3->setImg("0", "./images/img17449345652530_36X36R0.png", "");
	wMMSwitch3->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch3_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch4                 -----------------------------*/
	wMMSwitch4 = new STTButton(p_rt, wMPanel2, "播放下一个", 2);
	wMMSwitch4->setMainArg(136, 22, 36, 36, false);
	wMMSwitch4->setImg("1", "./images/button_10-1_36X36.gray.svg", "");
	wMMSwitch4->setImg("0", "./images/img17449589882780_36X36R0.png", "");
	wMMSwitch4->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch4_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch5                 -----------------------------*/
	wMMSwitch5 = new STTButton(p_rt, wMPanel2, "全屏模式", 2);
	wMMSwitch5->setMainArg(181, 22, 36, 36, false);
	wMMSwitch5->setImg("1", "./images/img17449612265420_36X36R0.png", "");
	wMMSwitch5->setImg("0", "./images/img17449609005430_36X36R0.png", "");
	wMMSwitch5->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch5_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch6                 -----------------------------*/
	wMMSwitch6 = new STTButton(p_rt, wMPanel2, "显示扩展设置", 2);
	wMMSwitch6->setMainArg(219, 22, 36, 36, false);
	wMMSwitch6->setImg("1", "./images/button_10-1_36X36.gray.svg", "");
	wMMSwitch6->setImg("0", "./images/img17449636461310_36X36R0.png", "");
	wMMSwitch6->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch6_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch7                 -----------------------------*/
	wMMSwitch7 = new STTButton(p_rt, wMPanel2, "切换播放列表", 2);
	wMMSwitch7->setMainArg(267, 23, 36, 36, false);
	wMMSwitch7->setImg("1", "./images/button_10-1_36X36.gray.svg", "");
	wMMSwitch7->setImg("0", "./images/img17449638575390_36X36R0.png", "");
	wMMSwitch7->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch7_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch8                 -----------------------------*/
	wMMSwitch8 = new STTButton(p_rt, wMPanel2, "循环方式", 2);
	wMMSwitch8->setMainArg(305, 23, 36, 36, false);
	wMMSwitch8->setImg("2", "./images/img17448799623320_36X36R0.png", "");
	wMMSwitch8->setImg("1", "./images/img17448799585480_36X36R0.png", "");
	wMMSwitch8->setImg("0", "./images/img17448792520620_36X36R0.png", "");
	wMMSwitch8->bindData(_V("循环方式"));
	wMMSwitch8->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch8_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch9                 -----------------------------*/
	wMMSwitch9 = new STTButton(p_rt, wMPanel2, "随机顺序播放", 2);
	wMMSwitch9->setMainArg(342, 23, 36, 36, false);
	wMMSwitch9->setImg("1", "./images/img17449652612660_36X36R0.png", "");
	wMMSwitch9->setImg("0", "./images/img17449652521140_36X36R0.png", "");
	wMMSwitch9->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch9_clk_cb);

	/*----------------------------- MSwitch : wMMSwitch10                -----------------------------*/
	wMMSwitch10 = new STTButton(p_rt, wMPanel2, "音量", 2);
	wMMSwitch10->setMainArg(871, 34, 24, 24, false);
	wMMSwitch10->setImg("3", "./images/img17449881204120_24X24R0.png", "");
	wMMSwitch10->setImg("2", "./images/img17449881154650_24X24R0.png", "");
	wMMSwitch10->setImg("1", "./images/img17449881115640_24X24R0.png", "");
	wMMSwitch10->setImg("0", "./images/img17449881074860_24X24R0.png", "");
	wMMSwitch10->onEventHandler(Event::CLICKED, this, (EHandler) &Frm01::wMMSwitch10_clk_cb);

	/*----------------------------- Slider : wMSlider2                   -----------------------------*/
	wMSlider2 = new STTSlider(p_rt, wMPanel2, "音量");
	wMSlider2->setMainArg(902, 21, 104, 35, 50, 0, 100, false);
	wMSlider2->setMainStyle(0, 0xa0a0a0, 0xffffff, 0, 0, 0xa0a0a0, 0, 0x0, "./images/slidervol0_104X35R0.png");
	wMSlider2->setIndicStyle(0, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0xffffff, "./images/slidervol1_104X35R0.png");
	wMSlider2->setKnobStyle(0, 0x1a2b1, 0xffffff, 0, 0, 0x1a2b1, 0, 0x0, "./images/slidervol2_35X35R0.png", 0);
	wMSlider2->onEventHandler(Event::VALUE_CHANGED, this, (EHandler) &Frm01::wMSlider2_vch_cb);

	/*----------------------------- Label : wMLabel10                    -----------------------------*/
	wMLabel10 = new STTLabel(p_rt, wMPanel2, "wMLabel10");
	wMLabel10->setMainArg(902, 23, 50, 16, "50%", TextAlign::CENTER, LabelLongMode::CLIP, 30);
	wMLabel10->setFonts(0x0, 12, "文泉驿微米黑", 0);
	wMLabel10->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel10->setFormatText(TextAlign::CENTER, LabelLongMode::CLIP, 30);

	/*called after widget created.*/

	/*----------------------------- 变量消息 : wMVar1                     -----------------------------*/
	_V("播放状态")->valueChanged.connect(this, &Frm01::onwMVar1Changed);
	std::function<void()> diswMVar1 = [this]() {
		_V("播放状态")->valueChanged.disconnect(this, &Frm01::onwMVar1Changed);
	};
	addVarMsg(diswMVar1);

	/*----------------------------- 变量消息 : wMVar2                     -----------------------------*/
	_V("播放时长秒")->valueChanged.connect(this, &Frm01::onwMVar2Changed);
	std::function<void()> diswMVar2 = [this]() {
		_V("播放时长秒")->valueChanged.disconnect(this, &Frm01::onwMVar2Changed);
	};
	addVarMsg(diswMVar2);

	return; //createParts END
}

void Frm01::onLoad(){
	wMVideo2->setVarOfCmd("播放状态");

	wMTileView2->getStyle()->p_scrollbar->setMode(2);
	wMMSwitch1->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	vm->setChar("播放暂停", "0");//显示为播放图片

	wMMSwitch2->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch2->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch3->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch3->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch4->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch4->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch5->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch5->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch6->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch6->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch7->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch7->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch8->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch8->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了
	vm->setChar("循环方式", "0");//显示为不循环图片

	wMMSwitch9->getStyle()->p_bg->setColor(0xe0e0e0)->setOpa(255);//背景色有点带灰,设置其颜色及透明度
	wMMSwitch9->getStyle()->p_bg->setOpa(50, stt::constant::WidgetState::PRESSED);//设置一下按下状态的透明度就有效果了

	wMMSwitch10->setState("2");//音量默认50%
	wMVideo2->setAutoRestart(wMMSwitch8->getState()!="0");
}

bool Frm01::onClosing(){
	return true;
}

void Frm01::onDispose(){
}

/**根据循环方式、是否选中,得到播放列表,传入为空时,取循环方式按钮的状态值*/
vector<string> Frm01::getPlayList(string cycle) {
	if(cycle=="") cycle = wMMSwitch8->getState();//循环方式
	vector<string> vec;
	if(wMList1->getOptionCount()==0)return vec;//没有

	if(cycle == "0" || cycle == "2") {//不循环或单曲循环
		if(wMList1->getSelectedIndex()<0) {//未选中项,则取第一个
			vec.push_back(wMList1->getIds()[0]);
			return vec;
		} else {
			vec.push_back(wMList1->getSelectedValue());//加入选中项
			return vec;
		}
	} else if(cycle == "1") {//全循环
		return wMList1->getIds();
	}
	return vec;
}

/**play前调用一下,因为setPlayList会让循环模式失效*/
void Frm01::setCycleMode() {
	string cycle = wMMSwitch8->getState();//循环方式
	if(cycle == "0") {
		wMVideo2->setAutoRestart(false);
	} else {
		wMVideo2->setAutoRestart(true);
	}
}

void Frm01::fullScreen() {
	Area area = Util::getScrSize();
	int w = area.w;
	int h = area.h;
	cout<<w<<"*"<<h<<endl;
	wMTileView2->setPos(0, 0);
	wMTileView2->setSize(w, h);
	wMPanel4->setSize(w, h);
	wMVideo2->setSize(w, h);
	wMVideo2->setImgSize(w, h);
}

void Frm01::restoreScreen() {
	Area area = Util::getScrSize();
	int w = area.w;
	int h = 488;
	wMTileView2->setPos(0, 24);
	wMTileView2->setSize(w, h);
	wMPanel4->setSize(w, h);
	wMVideo2->setSize(w, h);
	wMVideo2->setImgSize(w, h);
}


#include "util/FileUtil.h"
#include "util/StringUtil.h"
#include "util/DateUtil.h"

void Frm01::wMButton1_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton1(刷新媒体列表)的点击事件*/
	vector<string> paths;
#if __arm__
	paths.push_back("/customer");//搜索客户目录
	paths.push_back("/vendor");//搜索外设目录
#else
	paths.push_back("./images");//搜索图片目录
	paths.push_back("./res");//搜索资源目录
#endif
	vector<KV_Str_Str> ret;
	for(string path: paths) {
		FileUtil::getPathContent(path,ret);//搜索,注意文件太多可能会慢
	}
	wMList1->clearOptions();//清空一下
	for(KV_Str_Str kv: ret) {
		string filepath = kv.v + "/" + kv.k;
		if(StringUtil::endWith(filepath, ".mp4")) {
			wMList1->addOption(filepath, filepath);//将mp4文件加入列表
		}
	}
}

void Frm01::wMButton4_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton4(删除选中媒体)的点击事件*/
	wMList1->removeOption(wMList1->getSelectedValue());
}


void Frm01::wMMSwitch1_clk_cb(uint16_t code, LvEvent e) {
	/*开始暂停按钮*/
	int vstate = wMVideo2->getCmd();//获取当前播放状态

	switch(vstate) {
		case 0://开始->暂停(点击暂停按钮)
		{
			cout<<"[pause1]"<<endl;
			vm->setChar("播放暂停", "0");//显示为播放图片
			cout<<"[pause2]"<<endl;
			wMVideo2->pause();//暂停
			cout<<"[pause3]"<<endl;
			break;
		}

		case 1://停止->开始(点击开始按钮)
		{
			vector<string> vec = this->getPlayList();
			if(vec.size() == 0) {//没有列表项
				wMTileView2->setTileIndex(1, false);//跳转到列表页
			} else {
				cout<<"[start1]"<<endl;
				vm->setChar("播放暂停", "1");//显示为暂停图片
				wMVideo2->setPlayList(vec);
				cout<<"[start2]"<<endl;
				setCycleMode();
				cout<<"[start3]"<<endl;
				wMVideo2->play();//开始播放
				cout<<"[start4]"<<endl;
				wMTileView2->setTileIndex(0, false);//跳转到播放页
			}
			break;
		}

		case 2://暂停->继续(点击开始按钮)
		{
			cout<<"[resume1]"<<endl;
			vm->setChar("播放暂停", "1");//显示为暂停图片
			cout<<"[resume2]"<<endl;
			wMVideo2->resume();//继续
			cout<<"[resume3]"<<endl;
			break;
		}
	}
}


void Frm01::wMMSwitch8_clk_cb(uint16_t code, LvEvent e) {
	/*循环方式点击*/
	string cycle = wMMSwitch8->getState();
	if(cycle=="0") {//不循环0->全部循环1
		vm->setChar("循环方式", "1");//显示为全循环图片
		wMVideo2->setAutoRestart(true);//自动重新播放
		vector<string> vec = this->getPlayList("1");
		for(string s:vec) {
			if(std::find(wMVideo2->playList.begin(), wMVideo2->playList.end(), s)==wMVideo2->playList.end()) {
				//没找到相同的,则加入播放清单
				wMVideo2->playList.push_back(s);
			}
		}
		for(string s:wMVideo2->playList) {
			cout<<"全部循环"<<endl;
			cout<<s<<endl;
		}

	} else if(cycle == "1") {//全循环1 -> 单循环2
		vm->setChar("循环方式", "2");//显示为单曲循环图片
		wMVideo2->setAutoRestart(true);//自动重新播放
		if(wMVideo2->getCmd()==0 || wMVideo2->getCmd()==2) {
			//正在播放,则移除其他没有播放的
			wMVideo2->removePlayList();
		} else {
			vector<string> vec = this->getPlayList("2");
			//停止中,则全部移除,并增加选中项或第一项
			wMVideo2->setPlayList(vec);
		}
		for(string s:wMVideo2->playList) {
			cout<<"单曲循环"<<endl;
			cout<<s<<endl;
		}

	} else if(cycle == "2") {//单循环2 -> 不循环0
		vm->setChar("循环方式", "0");//显示为不循环图片
		wMVideo2->setAutoRestart(false);//不自动重新播放
		if(wMVideo2->getCmd()==0 || wMVideo2->getCmd()==2) {
			//正在播放,则移除其他没有播放的
			wMVideo2->removePlayList();
		} else {
			vector<string> vec = this->getPlayList("0");
			//停止中,则全部移除,并增加选中项或第一项
			wMVideo2->setPlayList(vec);
		}
		for(string s:wMVideo2->playList) {
			cout<<"不循环"<<endl;
			cout<<s<<endl;
		}

	}
}

void Frm01::wMMSwitch3_clk_cb(uint16_t code, LvEvent e) {
	/*停止按钮*/
	vm->setChar("播放暂停", "0");//显示为播放图片
	wMVideo2->stop();//停止播放
}

/**
 * 自动播放下一首时, getCmdOfVar()变量发生变化:先停止,再播放下一首(如果是不循环,则停止)
 */
void Frm01::onwMVar1Changed(SttObject *org, IVariable *data) {
	/*变量消息*/
	string v = data->toStr();
	if(v == "0") {
		vm->setChar("播放暂停", "1");//显示为暂停图片
	} else {
		vm->setChar("播放暂停", "0");//显示为播放图片
	}

}

void Frm01::wMMSwitch2_clk_cb(uint16_t code, LvEvent e) {
	/*播放上一个*/
	//当循环方式为全部循环时有效
	wMVideo2->playPrev();
}

void Frm01::wMMSwitch4_clk_cb(uint16_t code, LvEvent e) {
	/*播放下一个*/
	//当循环方式为全部循环时有效
	wMVideo2->playNext();
}

void Frm01::wMMSwitch5_clk_cb(uint16_t code, LvEvent e) {
	/*全屏按钮,不支持直接修改尺寸,删除再创建控件*/
	//1.先得取当前状态
	int icmd = wMVideo2->getCmd();
	//2.记录当前播放文件及位置后停止播放
	int iplay = 0;
	double itime = 0;
	vector<string> playlist = wMVideo2->playList;
	if(icmd != 1) {//如果不是停止状态,记录后并停止
		iplay = wMVideo2->iPlaying;
		itime = wMVideo2->getPlayedSecond();
		wMVideo2->stop();
	}
	//3.删除控件
	delete wMVideo2;
	//4.重新创建,把创建代码复制过来
	wMVideo2 = new STTFFmpeg(p_rt, wMPanel4, "wMVideo2");
	wMVideo2->channel = 0;
	wMVideo2->setRotate(0);
	wMVideo2->setMainArg(0, 0, 1024, 488, "");
	wMVideo2->bindData(_V("播放时长秒"));
	//5.改变尺寸
	if(wMMSwitch5->getState()=="0") {
		this->fullScreen();
		wMMSwitch5->setState("1");
	} else {
		this->restoreScreen();
		wMMSwitch5->setState("0");
	}
	//6.重新播放(相关参数都要设置一把)
	wMVideo2->setVarOfCmd("播放状态");
	wMVideo2->setPlayList(playlist);
	wMVideo2->iPlaying = iplay;
	wMVideo2->setSrc(playlist[iplay].c_str());
	if(icmd != 1) {//如果不是停止状态,还原
		wMVideo2->setAutoRestart(wMMSwitch8->getState()!="0");
		wMVideo2->play();
		wMVideo2->gotoSec((int)itime);
		if(icmd == 2) {//如果是暂停状态,还原
			wMVideo2->pause();
		}
	}
}

void Frm01::wMMSwitch6_clk_cb(uint16_t code, LvEvent e) {
	/*高级设置,暂不支持*/
	pm->getMessageBox("some advance setting...")->show();
}

void Frm01::wMMSwitch7_clk_cb(uint16_t code, LvEvent e) {
	/*切换播放列表*/
	if(wMTileView2->getTileIndex()==0)
		wMTileView2->setTileIndex(1, false);//跳转到列表页
	else
		wMTileView2->setTileIndex(0, false);//跳转到播放页
}

void Frm01::wMMSwitch9_clk_cb(uint16_t code, LvEvent e) {
	if(wMMSwitch9->getState()=="0") {
		//设成随机播放
		wMMSwitch9->setState("1");//显示随机图标
		wMVideo2->setRandPlay(true);
	} else {
		//设成顺序播放
		wMMSwitch9->setState("0");//显示顺序图标
		wMVideo2->setRandPlay(false);
	}
}

void Frm01::wMSlider1_vch_cb(uint16_t code, LvEvent e) {
	/*播放进度条值变化 - 跳转到指定位置*/
	if(wMVideo2->playList.size() == 0) return;
	wMVideo2->pause();//先暂停
	wMVideo2->gotoSec(wMSlider1->getValue());//跳转
	wMVideo2->play();//播放
}

void Frm01::onwMVar2Changed(SttObject *org, IVariable *data) {
	/*变量消息 - 绑定了变量(播放时长秒),每秒执行一次*/
	double duration = wMVideo2->getDuration();//获取总时长
	int sec = (int)duration;//转整数
	wMSlider1->setRange(0, sec);//设置进度条最大值
	int iplayed;
	vm->getInt("播放时长秒", iplayed);//获取播放时长
	if(iplayed>0)
		wMLabel1->setText(DateUtil::convert2HMS(iplayed));//如果播放时长大于0,则转为时:分:秒
	if(sec>0)
		wMLabel2->setText(DateUtil::convert2HMS(sec));//如果总时长大于0,则转为时:分:秒
	if(iplayed>0 && sec>0) {
		wMLabel5->setText(DateUtil::convert2HMS(iplayed) + "/" + DateUtil::convert2HMS(sec));//右下角标签
	}
	if(wMVideo2->playList.size() > 0) {
		wMLabel3->setText(wMVideo2->playList[wMVideo2->iPlaying]);
	}
}

void Frm01::wMSlider2_vch_cb(uint16_t code, LvEvent e) {
	/*音量滑块变化*/
	int vol = wMSlider2->getValue();//获取滑块值
	wMVideo2->setVolume(vol);//设置音量
	wMLabel10->setText(to_string(vol) + "%");//设置音量百分比标签
	//分三段显示不同图片
	if(vol<34) {
		wMMSwitch10->setState("1");
	} else if (vol < 67) {
		wMMSwitch10->setState("2");
	} else {
		wMMSwitch10->setState("3");
	}
	//去掉重着色
	wMSlider2->getStyle()->p_bg->setImgRecolorOpa(0, stt::constant::Part::Indic);
}

void Frm01::wMMSwitch10_clk_cb(uint16_t code, LvEvent e) {
	/*按下音量按钮*/
	if(wMMSwitch10->getState() == "0") {//非静音(按下后)
		wMSlider2_vch_cb(code,e);//直接调用音量滑块的值变化方法
	} else {
		wMMSwitch10->setState("0");//显示静音图片
		wMVideo2->setVolume(0);//视频静音
		//静音时,重着色为灰色
		wMSlider2->getStyle()->p_bg->setImgRecolor(0x808080, stt::constant::Part::Indic);
		wMSlider2->getStyle()->p_bg->setImgRecolorOpa(240, stt::constant::Part::Indic);
	}
}
上一个
曲线图显示波形
下一个
源码
最近修改: 2025-07-23Powered by