QT + FFMPEG实现基本播放器(一):播放器基础界面实现

QT + FFMPEG实现基本播放器(一):播放器基础界面实现

使用QT制作播放器的界面,界面使用QOpenGLWidget进行视频显示,将视频的每帧数据转为QImage,然后发送给Widget将QImage显示出来。

想要将QImage显示在Widget上的话,需要重写panitEvent事件:

void VideoWidget::paintEvent(QPaintEvent * /*e*/)
{
    if (m_Image.isNull())
    {
        return;
    }

    QPainter painter(this);

    //在widget上进行绘制
    painter.drawImage(this->rect(), m_Image);

}

为了使画面显示流畅,重写定时器事件,定时刷新页面:

void VideoWidget::timerEvent(QTimerEvent * /*e*/)
{
    //进行页面刷新操作
    this->update();
}

设置文件打开动作:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    openFile = new QAction(tr("&Open"),this);

    connect(openFile,&QAction::triggered,this,&MainWindow::OpenFileHanle);

    ui->mainToolBar->addAction(openFile);

    this->setWindowTitle(tr("FFPlayer"));


}

文件操作槽函数实现

void MainWindow::OpenFileHanle()
{

    QFileDialog *OpenFileDialog = new QFileDialog(this,tr("Open File"),".");

    OpenFileDialog->setAttribute(Qt::WA_DeleteOnClose,1);

    QString strFileName = OpenFileDialog->getOpenFileName();

    if(!strFileName.isEmpty())
    {
        qDebug()<<strFileName;

        string strVideoPath = string((const char *)strFileName.toLocal8Bit()); //QString转string

        string strVideoName = strVideoPath.substr(strVideoPath.find_last_of('/') + 1, strVideoPath.find_last_of('\0'));

        //设置标题
        this->setWindowTitle(QString::fromLocal8Bit(strVideoName.c_str()));
    }

}

以下就是播放器的基础界面的图例,以后在基本功能实现之后将会进行界面美化工作:
播放器基础界面

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值