Unsolved 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 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 -
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:
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 ?