使用QMediaPlayer和QVideoWidget
QHBoxLayout *m_layout=
newQHBoxLayout(this);
QMediaPlayer *m_player = new QMediaPlayer(this);
m_player->setMedia(QUrl::fromLocalFile(QString::fromLocal8Bit("d:/QtTest/111.mp4")));
QVideoWidget *m_videoW = new QVideoWidget(this);
m_layout->addWidget(m_videoW);
this->setLayout(m_layout);
m_player->setVideoOutput(m_videoW);
m_videoW->show();
m_player->play();
代码写起来很简单,编译也能通过,但是运行就会出错
DirectShowPlayerService::doRender: Unresolved error code 0x80040266
如果文件路径不对或者文件名是中文的,则会显示如下错误:
DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x80004005 ()
网上查了下,
Qt 中的多媒体播放,底层是使用DirectShowPlayerService,所以安装一个DirectShow解码器,例如LAV Filters,就可以解决运行出错问题
相关帖子
http://bbs.csdn.net/topics/391040873
https://github.com/qyvlik/Flat.qml/issues/4
下载LAV Filters地址
http://forum.doom9.org/showthread.php?t=156191 里的
Binaries for the most recent version are available here:
Version 0.68.1:
Installer (both x86/x64) -- Zips:
32-bit &
64-bit
Download 3D Plugin:
32-bit &
64-bit
选择32bit或者64bit下
下载完安装后,再运行程序,运行无错误,能够正常播放视频。
转自:https://blog.csdn.net/qqwangfan/article/details/52469859