Vlc playing status



  • Hello..I am building a media player using vlc-qt.How can I know the current status(whether the video is playing or not) of player?I want to use that status and change icons of pause and play?Or how can I change the play/pause buttons when the video is running?Thanks..


  • Qt Champions 2016

    Hi
    What player?
    https://github.com/vlc-qt/examples/tree/master/simple-player
    You supply more details and code for us to help. :)



  • @mrjj Hello..I am using that vlc-qt code only.This is my play/pause function

    void SimplePlayer::on_pause_clicked(bool checked)
    {
        QIcon icon;
        icon.addPixmap(QPixmap("://icons/play.png"),QIcon::Normal,QIcon::On);
        icon.addPixmap(QPixmap("://icons/pause.png"),QIcon::Normal,QIcon::Off);
        ui->pause->setIcon(icon);
        ui->pause->setCheckable(true);
    }
    

    Problem with this code is if I didn't select file and click play button it changes to pause and then if i select a file,play/pause buttons are toggled(I mean they are interchanged as I clicked it before selecting the video file).So,how this problem can be sorted?


  • Qt Champions 2016

    Hi
    It seems you use On/off state, which as far as I remember if for checked/unchecked?

    so this part
    QIcon icon;
    icon.addPixmap(QPixmap("://icons/play.png"),QIcon::Normal,QIcon::On);
    icon.addPixmap(QPixmap("://icons/pause.png"),QIcon::Normal,QIcon::Off);
    ui->pause->setIcon(icon);

    should be moved to SimplePlayer constructor and set up once.

    then
    void SimplePlayer::on_pause_clicked(bool checked)
    {
    if ( ui->pause->isChecked() ... ( its on play currently)
    }



  • @mrjj Could you explain the on_pause_clicked function briefly? Thanks


  • Qt Champions 2016

    @abhay said in Vlc playing status:

    on_pause_clicked

    Im guessing a bit. It seems you have used buttons
    Checked feature and switch between 2 bitmaps if checked or not
    checked?

    So checking / unchecking the button should flip flop play/pause right ?

    So if u check the button its play else is pause or reverse.

    the on_pause_clicked is called when you click on the button.

    So in my world, the on_pause_clicked should start or stop the
    video and button should handle its icons on its own.

    But with a single function its hard to tell how you made it work. :)

    so I imagine something like
    void SimplePlayer::on_pause_clicked(bool checked)
    {
    if ( ui->pause->isChecked()
    STOPVIDEO()
    else
    STARTVIDEO()
    }

    Kind of.



  • @mrjj Thanks for sharing your suggestions :)
    Here is my changed simpleplayer.cpp code.I did what you said to do.But the same problem repeats again.

    #include <QFileDialog>
    #include <QInputDialog>
    
    #include <VLCQtCore/Common.h>
    #include <VLCQtCore/Instance.h>
    #include <VLCQtCore/Media.h>
    #include <VLCQtCore/MediaPlayer.h>
    #include <VLCQtCore/Enums.h>
    
    //#include "EqualizerDialog.h"
    
    #include "SimplePlayer.h"
    #include "ui_SimplePlayer.h"
    
    SimplePlayer::SimplePlayer(QWidget *parent)
        : QMainWindow(parent),
          ui(new Ui::SimplePlayer),
          _media(0)
    //      _equalizerDialog(new EqualizerDialog(this))
    {
        ui->setupUi(this);
    
        _instance = new VlcInstance(VlcCommon::args(), this);
        _player = new VlcMediaPlayer(_instance);
        _player->setVideoWidget(ui->video);
    //    _equalizerDialog->setMediaPlayer(_player);
    
        ui->video->setMediaPlayer(_player);
        ui->volume->setMediaPlayer(_player);
        ui->volume->setVolume(50);
    //    ui->seek->setMediaPlayer(_player);
    
        connect(ui->actionOpenLocal, &QAction::triggered, this, &SimplePlayer::openLocal);
    //    connect(ui->actionOpenUrl, &QAction::triggered, this, &SimplePlayer::openUrl);
    
    
        connect(ui->openLocal, &QPushButton::clicked, this, &SimplePlayer::openLocal);
    //    connect(ui->openUrl, &QPushButton::clicked, this, &SimplePlayer::openUrl);
        connect(ui->pause, &QPushButton::toggled, ui->actionPause, &QAction::toggle);
        connect(ui->stop, &QPushButton::clicked, _player, &VlcMediaPlayer::stop);
        QIcon icon;
        icon.addPixmap(QPixmap("://icons/play.png"),QIcon::Normal,QIcon::On);
        icon.addPixmap(QPixmap("://icons/pause.png"),QIcon::Normal,QIcon::Off);
        ui->pause->setIcon(icon);
        ui->pause->setCheckable(true);
    
    }
    SimplePlayer::~SimplePlayer()
    {
        delete _player;
        delete _media;
        delete _instance;
        delete ui;
    }
    
    void SimplePlayer::openLocal()
    {
        QString file =
                QFileDialog::getOpenFileName(this, tr("Open file"),
                                             QDir::homePath(),
                                             tr("Multimedia files(*)"));
    
        if (file.isEmpty())
            return;
    
        _media = new VlcMedia(file, true, _instance);
    
        _player->open(_media);
    }
    
    void VlcWidgetVolumeSlider::mousePressEvent(QMouseEvent *event)
    {
       // ...
        QSlider::mousePressEvent(event);
       // ...
    }
    void VlcWidgetVolumeSlider::mouseReleaseEvent(QMouseEvent *event)
    {
        // ...
        QSlider::mouseReleaseEvent(event);
       // ...
    }
    
    void SimplePlayer::on_checkBox_clicked(bool checked)
    {
        ui->checkBox->setCheckable(true);
        QObject::connect(ui->checkBox, SIGNAL(clicked(bool)), ui->groupBox, SLOT(setVisible(bool)));
    
    }
    
    void SimplePlayer::on_fullscreen_clicked(bool checked)
    {
    
        isFullScreen() ? showNormal() : showFullScreen();
        QIcon ico;
        ico.addPixmap(QPixmap("://icons/full_in.png"),QIcon::Normal,QIcon::On);
        ico.addPixmap(QPixmap("://icons/full_out.png"),QIcon::Normal,QIcon::Off);
        ui->fullscreen->setIcon(ico);
        ui->fullscreen->setCheckable(true);
    }
    
    void SimplePlayer::on_pause_clicked(bool checked)
    {
        
        if(ui->pause->isChecked()){
           connect(ui->stop, &QPushButton::clicked, _player, &VlcMediaPlayer::stop);
        }
        else{
            connect(ui->actionPause, &QAction::toggled, _player, &VlcMediaPlayer::togglePause);
        }
    }
    

    What may be the problem?


  • Qt Champions 2016

    Hi
    That would only try to connect some signals , but not really do anything.

    I would expect something like

    void SimplePlayer::on_pause_clicked(bool checked)
    {
       
        if(ui->pause->isChecked()){
         _player ->stop();
        }
        else{
        _player ->togglePause();
        }
    }
    


  • @mrjj that's not working and the whole video stops while clickng the button.I want it to just pause at that moment.There's a separate button for stop


  • Qt Champions 2016

    @abhay
    ok then just call
    player ->togglePause(); ?



  • @mrjj I found that there's play and pause functions in core library.I changed to

    if(ui->pause->isChecked()){
            _player ->pause();
           }
           else{
           _player ->play();
           }
    

    and it worked.Thanks :)


  • Qt Champions 2016

    @abhay
    super :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.