我在“iosVideoTest /”文件夹中设置了一个小项目,以便在Qt / iOS应用中播放视频:
iosVideoTest.pro:
QT += core gui multimedia multimediawidgets
QTPLUGIN += qavfmediaplayer
CONFIG += mobility
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = iosVideoTest
TEMPLATE = app
SOURCES += main.cpp
HEADERS +=
deployment.files = ../iosVideoTest/media/9d0386eada217cd63a752458aeca89d6.mp4
deployment.path =
QMAKE_BUNDLE_DATA += deployment
main.cpp中:
#include <QApplication>
#include <QMainWindow>
#include <QMediaPlayer>
#include <QUrl>
#include <QVideoWidget>
int main(int argc, char *argv[]){
QApplication a(argc, argv);
QMainWindow w;
QVideoWidget* pVWidget = new QVideoWidget;
QMediaPlayer* pPlayer = new QMediaPlayer;
// with the following line a video is playing
pPlayer->setMedia(QUrl("http://www.rmh.de/9d0386eada217cd63a752458aeca89d6/9d0386eada217cd63a752458aeca89d6.mp4"));
// either of the following lines renders only a black screen
// pPlayer->setMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + "9d0386eada217cd63a752458aeca89d6.mp4"));
// pPlayer->setMedia(QUrl::fromLocalFile("9d0386eada217cd63a752458aeca89d6.mp4"));
pPlayer->setVideoOutput(pVWidget);
w.setCentralWidget(pVWidget);
w.show();
pPlayer->play();
return a.exec();
}
我已将视频http://www.rmh.de/9d0386eada217cd63a752458aeca89d6/9d0386eada217cd63a752458aeca89d6.mp4复制到项目文件夹中的./media目录。
使用视频的网址工作。 但是,将视频捆绑在应用程序内并使用本地文件名只会呈现黑屏。
编辑:使用图像(位于./iosVideoTest/media/img.png),通过QMAKE_BUNDLE_DATA将其捆绑并将其用作带有QLabel / QPixmap的本地文件,就像魅力一样......
有人能指出我使用本地视频文件的正确方向吗?
此致 汤姆