如题,我从网上参考了相关教程自己写了一个(原码在最后),是在Deepin环境下,编译是没错的,结果运行时弹出的窗口是全黑的,视频播放不出来,但奇怪的是有声音,即使把窗口关了也还有声音。如果我换到windows环境下,把相关的库和文件都改成windows的,也是没有报错,但直接连黑窗口都弹不出来了。我用的Qt5.9.1,创建工程时用的是QWidget基类(用其他的没写出来)。在百度上找了很长时间,说是没有gstreamer0.10-ffmpeg解码器,我试过了,这个解码器根本就下载不了。截图如下:
关于安装这个解码器的问题,百度说直接从官网上找安装包手动下载,我把好多安装包下载完了,结果都提示不能安装:
又有说是源的问题,我从网上找了好多源,然后挨个换,都不能安装。还有说系统要升级到最新,可是我也升级了啊,也没什么用。不想放弃,希望得到指点,如果能得到任何帮助,我将不胜感激。
原码如下:
那个player.ui我只是画了一些按钮,没有去实现,因为在播放这块儿卡住了。
这是.pro文件:
#-------------------------------------------------
#
Project created by QtCreator 2017-07-15T09:24:24
#
#-------------------------------------------------
QT += core gui\
multimedia\
multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test5
TEMPLATE = app
The following define makes your compiler emit warnings if you use
any feature of Qt which as been marked as deprecated (the exact warnings
depend on your compiler). Please consult the documentation of the
deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
You can also make your code fail to compile if you use deprecated APIs.
In order to do so, uncomment the following line.
You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
player.cpp
HEADERS += \
player.h
FORMS += \
player.ui
#ifndef PLAYER_H
#define PLAYER_H
#include <QWidget>
#include <QMediaPlayer>
#include <QVideoWidget>
namespace Ui {
class Player;
}
class Player : public QWidget
{
Q_OBJECT
public:
explicit Player(QWidget *parent = 0);
~Player();
private:
Ui::Player *ui;
QVideoWidget *videow;
QMediaPlayer *player;
};
#endif // PLAYER_H
```这是main.cpp:
#include "player.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Player w;
w.show();
return a.exec();
}
```这是player.cpp:
#include "player.h"
#include "ui_player.h"
Player::Player(QWidget *parent) :
QWidget(parent),
ui(new Ui::Player)
{
ui->setupUi(this);
videow = new QVideoWidget();
player = new QMediaPlayer();
player->setVideoOutput(videow);
player->setMedia(QUrl::fromLocalFile(QStringLiteral("/home/joe/Videos/U6-1.mpg")));
videow->show();
player->play();
}
Player::~Player()
{
delete ui;
}