您的位置:首页 > 编程语言 > Qt开发

QMediaPlayer视频播放器

2016-03-25 10:41 639 查看
.pro 工程文件中记得加上:

QT       +=  multimedia multimediawidgets


包含头文件:

#include <QMediaPlayer>
#include <QVideoWidget>


核心代码

QWidget *widget = new QWidget;
widget->resize(400, 300);   //

QVBoxLayout *layout = new QVBoxLayout;
QMediaPlayer* player = new QMediaPlayer;
QVideoWidget* vw = new QVideoWidget;

layout->addWidget(vw);
widget->setLayout(layout);
player->setVideoOutput(vw);

//    QFile file("D://1.mp4");
//    if(!file.open(QIODevice::ReadOnly))
//        qDebug() << "Could not open file";

player->setMedia(QUrl::fromLocalFile("D://1.mp4"));
player->play();
widget->show();


运行的时候会报这个错:

DirectShowPlayerService::doRender: Unresolved error code 80040266


原因是因为Qt 在windows上的多媒体播放功能是使用系统的DirectShow,所以安装或者更新DirectShow解码器就行了。

软件名: LAVFilters-0.65.exe

安装后就可完美运行视频播放了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt 视频