文章目录
- UI设计流程图
- UI设计界面
- 点击播放功能实现
UI设计流程图
UI设计界面
-
主界面
-
控制条
-
播放列表
-
画面显示
-
标题栏
-
设置界面
-
提示框
点击播放功能实现
槽函数实现:
connect(ui->ctrlBarWind, &CtrlBar::SigPlayOrPause, this, &MainWind::OnPlayOrPause);
ctrbar.h
class CtrlBar : public QWidget
{
Q_OBJECT
public:
explicit CtrlBar(QWidget *parent = 0);
~CtrlBar();
signals:
void SigPlayOrPause(); // 先实现这个
private slots:
void on_playOrPauseBtn_clicked();
void on_stopBtn_clicked();
private:
Ui::CtrlBar *ui;
};
ctrbar.cpp
CtrlBar::CtrlBar(QWidget *parent) :
QWidget(parent),
ui(new Ui::CtrlBar)
{
ui->setupUi(this);
}
CtrlBar::~CtrlBar()
{
delete ui;
}
void CtrlBar::on_playOrPauseBtn_clicked()
{
qDebug() << "on_playOrPauseBtn_clicked";
emit SigPlayOrPause(); // 发送信号
}
mainwid.h
class MainWind : public QMainWindow
{
Q_OBJECT
public:
explicit MainWind(QWidget *parent = 0);
~MainWind();
int InitSignalsAndSlots();
void OnPlayOrPause();
private:
Ui::MainWind *ui;
IjkMediaPlayer *mp_ = NULL;
};
mainwind.cpp
MainWind::MainWind(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWind)
{
ui->setupUi(this);
// 初始化信号槽相关的
InitSignalsAndSlots();
}
MainWind::~MainWind()
{
delete ui;
}
int MainWind::InitSignalsAndSlots()
{
connect(ui->ctrlBarWind, &CtrlBar::SigPlayOrPause, this, &MainWind::OnPlayOrPause);
}
int MainWind::message_loop(void *arg)
{
IjkMediaPlayer *mp = (IjkMediaPlayer *)arg;
while (1) {
AVMessage msg;
int retval = mp->ijkmp_get_msg(&msg, 1);
if (retval < 0)
break;
switch (msg.what) {
case FFP_MSG_PREPARED:
mp->ijkmp_start();
break;
default:
break;
}
msg_free_res(&msg);
}
void MainWind::OnPlayOrPause()
{
int ret = 0;
// 1. 先检测mp是否已经创建
if(!mp_) {
mp_ = new IjkMediaPlayer();
//1.1 创建
ret = mp_->ijkmp_create(std::bind(&MainWind::message_loop, this, std::placeholders::_1));
if(ret <0) {
delete mp_;
mp_ = NULL;
return;
}
// 1.2 设置url
mp_->ijkmp_set_data_source("m1.mp3");
// 1.3 准备工作
ret = mp_->ijkmp_prepare_async();
if(ret <0) {
delete mp_;
mp_ = NULL;
return;
}
} else {
// 已经准备好了,则暂停或者恢复播放
}
}