我编写了一个程序,该程序应该使用 QT 显示视频和音频。但是我无法弄清楚为什么视频没有播放,而音频工作正常。
vidpb.pro
QT += core gui multimedia multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = vidpb
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
CONFIG += mobility
MOBILITY = multimedia
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class QMediaPlayer;
class QVideoWidget;
class MainWindow : public QMainWindow
{
Q_OBJECT
QMediaPlayer *player;
QVideoWidget *widget;
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QtMultimedia>
#include <qvideowidget.h>
#include "qmediaplayer.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
player = new QMediaPlayer(this);
player->setMedia(QUrl::fromLocalFile("/sdcard/Movies/video1.mp4"));
widget = new QVideoWidget(this);
player->setVideoOutput(widget);
widget->show();
setCentralWidget(widget);
this->show();
player->play();
}
MainWindow::~MainWindow()
{
delete ui;
}