如何解决Qt QMediaPlayerRTSP客户端检查是否需要凭据才能连接到RTSP服务器
我已经使用Gstreamer编写了RTSP服务器,该服务器可能设置了凭据,也可能没有设置用于连接到它的凭据。 我还使用Qt QMediaPlayer和Qt gstreamer绑定编写了RTSP客户端。
现在,如果RTSP服务器已设置凭据,那么我想在RTSP客户端中显示一个输入用户名和密码的窗口。如果在RTSP服务器中未设置凭据,那么我不想在客户端中显示此窗口。
在我的RTSP客户端中,如何检查RTSP服务器是否需要凭据。
我想修改“ setRtspServerPath”方法以检查RTSP服务器是否需要凭据。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QInputDialog>
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("Super Nova Stream Viewer");
ui->filePathText->setText("");
player = new QMediaPlayer(this);
videoWidget = new QVideoWidget(this);
player->setVideoOutput(videoWidget);
ui->horizontalLayout->addWidget(videoWidget);
connect(player,&QMediaPlayer::durationChanged,ui->durationSlider,&QSlider::setMaximum);
connect(player,&QMediaPlayer::positionChanged,&QSlider::setValue);
connect(ui->durationSlider,&QSlider::sliderMoved,player,&QMediaPlayer::setPosition);
connect(player,ui->durationProgressBar,&QProgressBar::setMaximum);
connect(player,&QProgressBar::setValue);
}
MainWindow::~MainWindow()
{
delete ui;
}
***void MainWindow::setRtspServerPath(const QString& path)***
{
ui->filePathText->setText(path);
const QUrl url = QUrl(path);
const QNetworkRequest requestRtsp1(url);
player->setMedia(requestRtsp1);
}
void MainWindow::setMediaFilePath(const QString& path)
{
ui->filePathText->setText(path);
const QUrl url = QUrl::fromLocalFile(path);
player->setMedia(url);
}
void MainWindow::on_playButton_clicked()
{
player->play();
ui->volumeSlider->setSliderPosition(player->volume());
}
void MainWindow::on_pauseButton_clicked()
{
player->pause();
}
void MainWindow::on_stopButton_clicked()
{
player->stop();
ui->volumeSlider->setSliderPosition(0);
}
void MainWindow::on_muteUnmuteButton_clicked()
{
if (player->isMuted())
{
player->setMuted(false);
ui->muteUnmuteButton->setText("Mute");
}
else
{
player->setMuted(true);
ui->muteUnmuteButton->setText("UnMute");
}
}
void MainWindow::on_volumeSlider_valueChanged(int value)
{
player->setVolume(value);
}
void MainWindow::on_actionOpenNetworkStream_triggered()
{
QString serverPath = QInputDialog::getText(this,"Rtsp Server","Rtsp Server Address");
setRtspServerPath(serverPath);
}
void MainWindow::on_actionOpenFile_triggered()
{
QString file = QFileDialog::getOpenFileName(this,"Open Media File","","Video files (*.mp4)");
setMediaFilePath(file);
}
void MainWindow::on_forwardButton_clicked()
{
player->setPlaybackRate(2.0);
}
void MainWindow::on_backwardButton_clicked()
{
player->setPlaybackRate(-1.0);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。