Qt does not play video
Solved
General and Desktop
-
Hi!
Qt does not play video.
How to play video?
This myCode.#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtMultimedia/QMediaPlayer> #include <QtMultimedia/QMediaPlaylist> #include <QtMultimediaWidgets/QVideoWidget> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QMediaPlayer *player = new QMediaPlayer; QMediaPlaylist *playlist = new QMediaPlaylist(player); playlist->addMedia(QUrl("C:/Users/New Owner/Downloads/example.mp4")); playlist->addMedia(QUrl("C:/Users/Public/Videos/Sample Videos/Живая природа.wmv")); QVideoWidget *videoWidget = new QVideoWidget(this); videoWidget->setSizeIncrement(600,600); player->setVideoOutput(videoWidget); videoWidget->show(); playlist->setCurrentIndex(0); player->play(); } MainWindow::~MainWindow() { delete ui; }
This too not works
QMediaPlayer* player = new QMediaPlayer(this); QGraphicsVideoItem *item = new QGraphicsVideoItem; player->setVideoOutput(item); QGraphicsView * graphicsView = new QGraphicsView(this); graphicsView->scene()->addItem(item); graphicsView->show(); player->setMedia(QUrl("C:/Users/Public/Videos/Sample Videos/Живая природа.wmv")); player->play();
-
Hi,
Try with
QUrl::fromLocalFile
. -
its too not works
QMediaPlayer *player = new QMediaPlayer; QMediaPlaylist *playlist = new QMediaPlaylist(player); playlist->addMedia(QUrl::fromLocalFile("C:/Users/New Owner/Downloads/example.mp4")); playlist->addMedia(QUrl::fromLocalFile("C:/Users/New Owner/Downloads/example.wmv")); QVideoWidget *videoWidget = new QVideoWidget(this); videoWidget->setSizeIncrement(600,600); player->setVideoOutput(videoWidget); videoWidget->show(); playlist->setCurrentIndex(1); player->play();
but this works
#include <QApplication> #include <QMainWindow> #include <QVideoWidget> #include <QMediaPlayer> #include <QMediaPlaylist> int main(int argc, char * argv[]) { QApplication testApp(argc, argv); QMainWindow w; QVideoWidget videoWidget(&w); w.setCentralWidget(&videoWidget); QMediaPlayer *player = new QMediaPlayer(&w); player->setMedia( QUrl::fromLocalFile("E:\\big_buck_bunny.mp4") ); player->setVideoOutput(&videoWidget); w.show(); player->play(); return testApp.exec(); }
How do I move this solution to a class method?
-
Its work,but how to stretch QMediaPlayer to the whole window?
QMediaPlayer *player = new QMediaPlayer(this); QVideoWidget *videoWidget = new QVideoWidget(this); videoWidget->setSizeIncrement(900,900); player->setVideoOutput(videoWidget); videoWidget->show(); player->setMedia( QUrl::fromLocalFile("C:/Users/New Owner/Downloads/example.wmv") ); player->play();