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. Retrieve audio duration
Forum Updated to NodeBB v4.3 + New Features

Retrieve audio duration

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Marek
    wrote on last edited by A Former User
    #1

    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 qtcentre.org
    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
    Marek

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eti_nne
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marek
        wrote on last edited by Marek
        #3

        no actually what I did is:

            connect(player,SIGNAL(durationChanged(qint64)),this,SLOT(fileDuration(qint64)));
            player->setMedia(QUrl::fromLocalFile(file_name));
            player->setMuted(true);
            player->play();
        

        and then catch signal and stop player

        void FileCfgMgr::fileDuration(qint64 duration) {
            disconnect(player,SIGNAL(durationChanged(qint64)),this,SLOT(fileDuration(qint64)));
            player->stop();
            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 ?

        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