QT播放视频程序

QT播放视频程序

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 
#include 
#include 
#include 
#include 


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H

main.cpp

#include "mainwindow.h"
#include 
#include
#include "form.h"
#include

QDesktopWidget *desk = QApplication::desktop();


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
//    QDesktopWidget *desktop = QApplication::desktop();

//    int N = desktop->screenCount();

    MainWindow w;
    w.show();
    Form second;
///显示第二屏幕
//    if(N>0)
//    {
//     second.setGeometry(desktop->screenGeometry(1));
//     second.show();
//     qDebug()<setAspectRatioMode(Qt::IgnoreAspectRatio);
    videoWidget->setFullScreen(true);
    laa->addWidget(videoWidget);
    widget->setLayout(laa);
    playlist->addMedia(QUrl::fromLocalFile("/添加movec指令.mp4"));
    player->setVideoOutput(videoWidget);
    player->setPlaylist(playlist);
    videoWidget->show();
    playlist->setCurrentIndex(0);
    widget->showFullScreen();
    widget->setGeometry(desk->screenGeometry(1));
    player->play();



    return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "form.h"
#include 
#include 
#include 
#include 
#include 
#include
#include
#include
#include


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);





}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
//   QWidget* widget=new QWidget;
//   QMediaPlayer *player=new QMediaPlayer;
//   QMediaPlaylist *playlist=new QMediaPlaylist;
//   QVideoWidget *videoWidget=new QVideoWidget;
//   QVBoxLayout*laa=new QVBoxLayout;

//videoWidget->setAspectRatioMode(Qt::IgnoreAspectRatio);
//videoWidget->setFullScreen(true);
//laa->addWidget(videoWidget);
//widget->setLayout(laa);

//   playlist->addMedia(QUrl::fromLocalFile("F:\\添加movec指令.mp4"));//两种添加路经的方式
//   playlist->addMedia(QUrl::fromLocalFile("/添加movec指令.mp4"));
// playlist->addMedia(QUrl::fromLocalFile("E:\\move\\01.mp4"));
//   player->setVideoOutput(videoWidget);
//   player->setPlaylist(playlist);
//   videoWidget->show();
//   playlist->setCurrentIndex(0);
//   widget->showFullScreen();
//   widget->setGeometry(desk->screenGeometry(1));
//   player->play();
   qDebug()<<"aaaa";

}

void MainWindow::on_pushButton_2_clicked()
{

}

mainwindow.ui



 MainWindow
 
  
   
    0
    0
    400
    300
   
  
  
   MainWindow
  
  
   
    
     
      20
      160
      75
      23
     
    
    
     打开视频1 
    
   
   
    
     
      120
      160
      75
      23
     
    
    
     打开视频2
    
   
  
  
   
    
     0
     0
     400
     23
    
   
  
  
   
    TopToolBarArea
   
   
    false
   
  
  
 
 
 
 


你可能感兴趣的:(qt5)