我在文件夹“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
主.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 的本地文件,就像一个魅力......</p>
谁能指出我使用本地视频文件的正确方向?
问候,汤姆