Congratulations to our 2022 Qt Champions!

Retrieve audio duration

  • Hi

    I can't find a way to get duration of audio file without actually playing it.
    I have searched the web, last question was at
    But it seems there is no answer how to get it, QMediaContent does not provide anything
    QMediaPlayer::duration gives -1, signal durationChanged gives this value but I have to play the file.

    Best Regards

  • I don't think you can get the duration of a mediacontent from the player without playing it..

    But you can get it from the QMediaPlaylist or the QMediaContent before asking the player to read it.

    How do you define the media content for the player ?

  • no actually what I did is:


    and then catch signal and stop player

    void FileCfgMgr::fileDuration(qint64 duration) {
        ui->rc_fileDesc->setText(tr("seconds %1").arg(duration/1000);

    so dirty hack ;)

    Documentation for QMediaContent does not say anything, I mean some function, property ?
    Neither in QMediaPlaylist nor in QMediaContent I can't see any function/property to get duration of the audio file.
    Am I missing something ?

Log in to reply