我正在开发一个Qt
以vlc-qt
模块为基础的媒体播放器。所以我可以在 中加载视频VlcWidgetVideo
并使用WidgetSeekProgress
来显示视频的经过时间和完整时间。
问题是在创建视频并将其加载到小部件后,当我创建 的对象时WidgetSeekProgress
,它不会显示视频的完整视频时间和经过的时间。它只是显示没有时间在它的左边和右边的栏。我的示例项目的代码如下
explayer.h
#ifndef EXPPLAYER_H
#define EXPPLAYER_H
#include <QMainWindow>
#include "VLCQtCore/Instance.h"
#include "VLCQtCore/MediaPlayer.h"
#include "VLCQtCore/Media.h"
#include "VLCQtCore/Common.h"
#include "VLCQtCore/Config.h"
#include "QPushButton"
#include "QtMultimedia/QMediaPlaylist"
#include "VLCQtWidgets/WidgetVideo.h"
#include "VLCQtWidgets/WidgetSeekProgress.h"
#include "QSlider"
#include "QFileDialog"
#include "QInputDialog"
#include "QLabel"
#include "QListView"
#include "QBoxLayout"
QT_BEGIN_NAMESPACE
namespace Ui { class expPlayer; }
QT_END_NAMESPACE
class expPlayer : public QMainWindow
{
Q_OBJECT
public:
expPlayer(QWidget *parent = nullptr);
~expPlayer();
private slots:
void on_pushButton_clicked();
private:
Ui::expPlayer *ui;
VlcInstance *m_instance;
VlcMedia *m_media;
VlcMediaPlayer *m_player;
VlcWidgetSeekProgress *m_progressBar;
};
#endif // EXPPLAYER_H
explayer.cpp
#include "expplayer.h"
#include "ui_expplayer.h"
expPlayer::expPlayer(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::expPlayer)
{
ui->setupUi(this);
m_instance = new VlcInstance(VlcCommon::args(), this);
m_player = new VlcMediaPlayer(m_instance);
m_player->setVideoWidget(ui->m_video);
ui->m_video->setMediaPlayer(m_player);
ui->m_video->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->m_video->show();
m_media = new VlcMedia("file:///home/vinay/Downloads/long_sample_video.mp4",m_instance);
m_player->open(m_media);
m_player->play();
}
expPlayer::~expPlayer()
{
delete ui;
}
void expPlayer::on_pushButton_clicked()
{
m_progressBar=new VlcWidgetSeekProgress(m_player,this);
m_progressBar->resize(ui->m_video->width(),30);
m_progressBar->move(ui->m_video->x(),ui->m_video->y()+ui->m_video->height()+20);
m_progressBar->show();
}
我通过单击 UI 中的按钮来创建进度条的实例,因为我认为视频没有按时加载。所以我的酒吧没有显示时间。