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. Two durations of QMediaPlayer file

Two durations of QMediaPlayer file

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmediaplayerproblem
3 Posts 2 Posters 866 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.
  • N Offline
    N Offline
    Nvie
    wrote on 18 Jan 2019, 17:44 last edited by Nvie
    #1

    Hello. I'm creating a music player and I have come across a strange problem. From what I know there are two possible ways of getting the duration of the QMediaPlayer file, by the duration() function and the metadata. They are varying in the duration by small numbers but my case is different. The duration of the file (from QMediaPlayer) is almost 4 times longer than the real one. For example:

    Duration by the function: 907826
    Duration by the metadata: 218567

    But still, the music ends after 3:38, not 15:07. This creates problems with the progress slider and the timer. I also checked is the same problem appears in the qt music player example and it's there too. I actually have the duration problem with the single mp3 file (rest of the mp3 files with metadata are working fine).

    Here comes part of the code if it would help anything:

    // progress - QSlider
    // musicMedia - QMediaPlayer
    
    connect(musicMedia, &QMediaPlayer::durationChanged, this, &MainWindow::on_durationChanged);
    connect(musicMedia, &QMediaPlayer::positionChanged, this, &MainWindow::on_positionChanged);
    
    void  MainWindow::on_positionChanged(int position)
    {
          ui->progress->setValue(position);
    }
    
    void  MainWindow::on_durationChanged(int duration)
    {
        ui->progress->setRange(0, duration);
    
        //or
    
       // ui->progress->setRange(0, musicMedia->metaData("Duration").toInt());
    }
    
    void MainWindow::on_progress_sliderMoved(int position)
    {
       musicMedia->setPosition(position);
    }
    
    

    If I will use the metadata time and move the slider, the music will end too soon. If I will use the function duration then the music will end before the slider will finish. What should I do to avoid this and still get the real time for the timer?

    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Jan 2019, 20:25 last edited by
      #2

      Hi and welcome to devnet,

      Did you check what you get with that same file with other players likes VLC ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nvie
        wrote on 18 Jan 2019, 20:51 last edited by
        #3

        Thank you for the greeting.

        The file is working fine with the other players (VLC, Windows 10 player).

        1 Reply Last reply
        0

        1/3

        18 Jan 2019, 17:44

        • Login

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