Advertisement
Guest User

Untitled

a guest
Oct 28th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////mainwindow.h
  2. #ifndef MAINWINDOW_H
  3. #define MAINWINDOW_H
  4.  
  5. #include <QMainWindow>
  6. #include <QMediaPlayer>
  7. #include <QVideoWidget>
  8. #include <QFileDialog>
  9. #include <QVBoxLayout>
  10. #include "myvideoobject.h"
  11.  
  12.  
  13. namespace Ui {
  14. class MainWindow;
  15. }
  16.  
  17. class MainWindow : public QMainWindow
  18. {
  19.     Q_OBJECT
  20.  
  21. public:
  22.     explicit MainWindow(QWidget *parent = nullptr);
  23.     ~MainWindow();
  24.  
  25. private slots:
  26.     void on_actionOpen_triggered();
  27.  
  28. private:
  29.     Ui::MainWindow *ui;
  30.  
  31.     QMediaPlayer* mediaPlayer;
  32.     QVideoWidget* videoWidget;
  33.     MyVideoObject* videoObject;
  34.  
  35. };
  36.  
  37. #endif // MAINWINDOW_H
  38.  
  39.  
  40. ///////////////////////////////////////////////////////mainwindow.cpp
  41. #include "mainwindow.h"
  42. #include "ui_mainwindow.h"
  43.  
  44. MainWindow::MainWindow(QWidget *parent) :
  45.     QMainWindow(parent),
  46.     ui(new Ui::MainWindow)
  47. {
  48.     ui->setupUi(this);
  49.  
  50.     mediaPlayer = new QMediaPlayer(this);
  51.  
  52.     videoObject = new MyVideoObject(this);
  53.     ui->horizontalLayout_5->addWidget(videoObject);
  54.     videoObject->resize(500,400);
  55.     mediaPlayer->setVideoOutput(videoObject);
  56. }
  57.  
  58. MainWindow::~MainWindow()
  59. {
  60.     delete ui;
  61. }
  62.  
  63. void MainWindow::on_actionOpen_triggered()
  64. {
  65.     QString fileName = QFileDialog::getOpenFileName(this,"Select Video","","video Files (*.mp4)");
  66.  
  67.     mediaPlayer->stop();
  68.     mediaPlayer->setMedia(QUrl::fromLocalFile(fileName));
  69.  
  70.     mediaPlayer->play();
  71.  
  72. }
  73. ///////////////////////////////////////////////////////////// main.cpp
  74.  
  75.  
  76. #include "mainwindow.h"
  77. #include <QApplication>
  78.  
  79. int main(int argc, char *argv[])
  80. {
  81.     QApplication a(argc, argv);
  82.     MainWindow w;
  83.     w.show();
  84.  
  85.     return a.exec();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement