Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't get duration video with a QMediaPlayer

Can't get duration video with a QMediaPlayer

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.4k 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.
  • saxoalexS Offline
    saxoalexS Offline
    saxoalex
    wrote on last edited by saxoalex
    #1

    Hi everybody !
    I'm trying to get the duration of a video that I play with a QMediaPlayer but this don't work. I tried a lot of things like :
    myplayer->duration(quint64); but it didn't worked.

    I saw that I could do that with signals but whene I try, the application say this following error message : "
    signals :
    void QMediaPlayer::durationChanged(qint64 duration);

    Here is my cpp :

    //In a function 1
        videowidget = new QVideoWidget(this);
        player = new QMediaPlayer(videowidget);
        player -> setVideoOutput(videowidget);
        videowidget->setAspectRatioMode(Qt::KeepAspectRatio);
    
    //In a function 2
    player->setMedia(QUrl::fromLocalFile("/home/alexandre/Documents/qt/pt2_v3.1/video/decompte.mp4"));
          player->play();
          connect(player, SIGNAL(durationChanged(duration)), this, SLOT(Temps(to, duration)));
    

    Here is my class code :

    class Window : public QWidget
    {
    public :
        qint64 duration;
        QMediaPlayer *player;
        QVideoWidget *videowidget;
    };
    

    My function Temps :

    void Window::Temps(int to, qint64 duration)
    {
    
        //Countdown
        std::cout <<"Durée avant réduction="<<duration<< std::endl;
        time = duration - 10; // On retire 10s aux temps du media pour declencher les boutons avant
        std::cout << "Durée après réduction=" <<time<< std::endl;
    
        //Timer duraction
        timer = new QTimer;
        timer->setSingleShot(true);
        timer->start(time);
    
        connect(timer, &QTimer::timeout, [this, to]
        {
            this->Attente_boutons(to);
        });
    }
    

    There is many other thing in my code but they don't concern my player.

    Thank's !
    Alexandre.

    1 Reply Last reply
    0
    • saxoalexS Offline
      saxoalexS Offline
      saxoalex
      wrote on last edited by
      #2

      I tried that whithout my wired signal :

      void Window::Temps(int to)
      {
          std::cout<<"Passage par Temps"<<std::endl;
          qint64 duration=player->duration();
          std::cout<<"Duration="<<duration<<std::endl;
          Reini_boutons();
          //Compte à rebour
          time = duration - 10; // On retire 10s aux temps du media pour declencher les boutons avant
          std::cout << "Time=" <<time<< std::endl;
          //Declaration du timer
          timer = new QTimer;
          timer->setSingleShot(true);
          timer->start(time);
      
          connect(timer, &QTimer::timeout, [this, to]
          {
              this->Attente_boutons(to);
          });
      }
      

      time is a member qint64.

      Here,
      Duration=-1
      Time=-11

      raven-worxR 1 Reply Last reply
      0
      • saxoalexS saxoalex

        I tried that whithout my wired signal :

        void Window::Temps(int to)
        {
            std::cout<<"Passage par Temps"<<std::endl;
            qint64 duration=player->duration();
            std::cout<<"Duration="<<duration<<std::endl;
            Reini_boutons();
            //Compte à rebour
            time = duration - 10; // On retire 10s aux temps du media pour declencher les boutons avant
            std::cout << "Time=" <<time<< std::endl;
            //Declaration du timer
            timer = new QTimer;
            timer->setSingleShot(true);
            timer->start(time);
        
            connect(timer, &QTimer::timeout, [this, to]
            {
                this->Attente_boutons(to);
            });
        }
        

        time is a member qint64.

        Here,
        Duration=-1
        Time=-11

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @saxoalex
        then most probably the used codec can't determine the duration.
        Have you tried with another video file to check against?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • saxoalexS Offline
          saxoalexS Offline
          saxoalex
          wrote on last edited by
          #4

          Hi !
          I tried with a h264,mpeg2 and v210 codec. I have the same result...

          1 Reply Last reply
          0
          • saxoalexS Offline
            saxoalexS Offline
            saxoalex
            wrote on last edited by
            #5

            Someone have a solution please ?

            1 Reply Last reply
            0

            • Login

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