使用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