如果只播放一个视频,它就会成功。但是两个或三个,它就是失败。 我注意到QGraphicsVideoItem的文档:
注意:一次只能将一个显示输出连接到媒体对象。
所以,我想知道如何在QGraphicsView中叠加多个视频? 谢谢!
我的测试代码:
#include <QtWidgets/QApplication>
#include <QGraphicsScene>
#include <QGraphicsVideoItem>
#include <QMediaPlayer>
#include <QGraphicsView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(0,0,1920,1080);
QGraphicsVideoItem *item1 = new QGraphicsVideoItem;
QMediaPlayer * player1 = new QMediaPlayer;
player1->setVideoOutput(item1);
player1->setMedia(QUrl::fromLocalFile("C:/Users/Public/Videos/Sample Videos/1.wmv"));
player1->setVolume(0);
scene.addItem(item1);
item1->setPos(0,100);
QGraphicsVideoItem *item2 = new QGraphicsVideoItem;
QMediaPlayer * player2 = new QMediaPlayer;
player2->setVideoOutput(item2);
player2->setMedia(QUrl::fromLocalFile("C:/Users/Public/Videos/Sample Videos/2.wmv"));
player2->setVolume(0);
scene.addItem(item2);
item1->setPos(500,500);
QGraphicsView view;
view.setScene(&scene);
view.scale(0.3,0.3);
view.show();
player1->play();
player2->play();
return a.exec();
}
答案 0 :(得分:0)
我可以推荐一种可以在QGraphicsView上显示视频的方法。
QMediaPlayer *player1 = new QMediaPlayer(this);
QVideoWidget *video1 = new QVideoWidget(this);
QGraphicsVideoItem *item1 = new QGraphicsVideoItem;
QGraphicsView *view = new QGraphicsView(this);
player1->setVideoOutput(item1);
player1->setMedia(QUrl::fromLocalFile("C:/Users/Public/Videos/Sample Videos/1.wmv"));
player1->play();
view->setViewport(video1);
player1->setVideoOutput(video1);
view->show();