Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Vlc playing status

Vlc playing status

Scheduled Pinned Locked Moved Solved 3rd Party Software
12 Posts 2 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abhay
    wrote on last edited by
    #1

    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..

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      A 1 Reply Last reply
      1
      • mrjjM mrjj

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

        A Offline
        A Offline
        abhay
        wrote on last edited by abhay
        #3

        @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?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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)
          }

          A 1 Reply Last reply
          1
          • mrjjM mrjj

            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)
            }

            A Offline
            A Offline
            abhay
            wrote on last edited by
            #5

            @mrjj Could you explain the on_pause_clicked function briefly? Thanks

            mrjjM 1 Reply Last reply
            0
            • A abhay

              @mrjj Could you explain the on_pause_clicked function briefly? Thanks

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              A 1 Reply Last reply
              1
              • mrjjM mrjj

                @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.

                A Offline
                A Offline
                abhay
                wrote on last edited by abhay
                #7

                @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?

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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();
                      }
                  }
                  
                  A 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    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();
                        }
                    }
                    
                    A Offline
                    A Offline
                    abhay
                    wrote on last edited by
                    #9

                    @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

                    mrjjM 1 Reply Last reply
                    0
                    • A abhay

                      @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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

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

                      A 1 Reply Last reply
                      1
                      • mrjjM mrjj

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

                        A Offline
                        A Offline
                        abhay
                        wrote on last edited by
                        #11

                        @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 :)

                        mrjjM 1 Reply Last reply
                        2
                        • A abhay

                          @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 :)

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @abhay
                          super :)

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved