在这里,我要放置用Qt编写的代码,但是视频流无法正常工作。当IP放置在浏览器上时,视频可以完美显示,当我们运行该应用程序时,它没有任何输出。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QGridLayout>
#include <QMediaPlayer>
#include <QNetworkRequest>
#include <QVideoWidget>
#include <QNetworkAccessManager>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("IPCAM Video Streaming");
QVideoWidget *_vw1 = new QVideoWidget;
QMediaPlayer *_player1 = new QMediaPlayer;
QGridLayout *layout = new QGridLayout;
layout->addWidget(_vw1,0,0,1,1);
QWidget *win = new QWidget();
win->setLayout(layout);
setCentralWidget(win);
// QMediaPlayer -> QVideoWidget
_player1->setVideoOutput(_vw1);
const QUrl url1 = QUrl("http://ipaddress/mjpeg.cgi");
const QNetworkRequest requesturl1(url1);
_player1->setMedia(requesturl1);
_vw1->setGeometry(100,100,300,400);
_vw1->show();
_player1->play();
}
MainWindow::~MainWindow()
{
delete ui;
}