pro.文件
#-------------------------------------------------
#
# Project created by QtCreator 2018-12-26T15:51:22
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled2
TEMPLATE = app
QT += multimedia
QT += multimediawidgets
QT += axcontainer
SOURCES += main.cpp\
mainwindow.cpp \
form.cpp
HEADERS += mainwindow.h \
form.h
FORMS += mainwindow.ui \
form.ui
mainwindow.h文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "form.h"
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QMediaPlaylist>
#include <QtMultimedia>
#include <QtMultimediaWidgets>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Form ff;
// QWidget* widget=new QWidget;
QMediaPlayer *player=new QMediaPlayer;
QMediaPlaylist *playlist=new QMediaPlaylist;
QVideoWidget *videoWidget=new QVideoWidget;
QVBoxLayout*laa=new QVBoxLayout;
QDesktopWidget *desk = QApplication::desktop();
QTimer *update_time=new QTimer(this); //定义定时器类
qint64 bb;
private slots:
void on_pushButton_clicked();
void time1();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "form.h"
#include "ui_form.h"
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QMediaPlaylist>
#include <QtMultimedia>
#include <QtMultimediaWidgets>
#include<QDebug>
#include<QVBoxLayout>
#include<QWidget>
#include<QDesktopWidget>
#include"time.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
int N = desk->screenCount();
//显示第二屏幕
if(N>0)
{
ff.setGeometry(desk->screenGeometry(1));
ff.show();
qDebug()<<N;
}
videoWidget->setAspectRatioMode(Qt::IgnoreAspectRatio);
videoWidget->setFullScreen(true);
laa->addWidget(videoWidget);
ff.setLayout(laa);
playlist->addMedia(QUrl::fromLocalFile("E:\\move\\01.mp4"));//两种添加路经的方式
playlist->addMedia(QUrl::fromLocalFile("E:\\move\\02.mp4"));//两种添加路经的方式
playlist->addMedia(QUrl::fromLocalFile("E:\\move\\03.mp4"));//两种添加路经的方式
player->setVideoOutput(videoWidget);
player->setPlaylist(playlist);
videoWidget->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
playlist->setCurrentIndex(0); //设置播放视频内容
ff.showFullScreen(); //设置全屏显示
// ff.setGeometry(desk->screenGeometry(1));
player->play(); //开始播放
connect(update_time,SIGNAL(timeout()),this,SLOT(time1()));// 连接时间函数
update_time->start(1000); //定时1s
qDebug()<<"aaaa"; //打印内容
}
void MainWindow::time1()
{
bb=player->position();//获取视频进度
qDebug()<<bb;
}
void MainWindow::on_pushButton_2_clicked()
{
playlist->setCurrentIndex(1);
ff.showFullScreen();
// ff.setGeometry(desk->screenGeometry(1));
player->play();
connect(update_time,SIGNAL(timeout()),this,SLOT(time1()));// 连接时间函数
update_time->start(1000); //定时1s
}
void MainWindow::on_pushButton_3_clicked()
{
playlist->setCurrentIndex(2);
ff.showFullScreen();
// ff.setGeometry(desk->screenGeometry(1));
player->play();
connect(update_time,SIGNAL(timeout()),this,SLOT(time1()));// 连接时间函数
update_time->start(1000); //定时1s
}
main.cpp文件
#include "mainwindow.h"
#include <QApplication>
#include<QDesktopWidget>
#include "form.h"
#include<QDebug>
#include<QTimer>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
另外还有加上一个form窗口文件
显示窗口图