Search code examples
c++qtlibvlcvlc-qt

WidgetSeekProgress not showing the media elapsed and full time of Video Vlc-qt Qt


I am developing a media player in Qt using vlc-qt module as my base. So I am able to load the video in the VlcWidgetVideo and using the WidgetSeekProgress to show the elapsed time and full time of the video.

The problem is that after creating and loading the video into the widget, when I create the object of the WidgetSeekProgress, it doesn't show the full video time and elapsed time of the video. It just shows the bar with no time on it's left and right. Code of my example project is given below 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();

}

I create the instance of the progress bar by clicking a button in the UI because I thought video didn't load on time. So my bar is not showing me the time.


Solution

  • I just need to add the player into the WidgetSeekProgress object After the media player instantiation.

    m_instance = new VlcInstance(VlcCommon::args(), this);
        m_player = new VlcMediaPlayer(m_instance);
        ui->m_seek->setMediaPlayer(m_player);