3

How to get the total time of an audio file? I am trying this:

QMediaPlayer* audioPlayer = new QMediaPlayer();
audioPlayer->setMedia(QUrl::fromLocalFile("F:/Audio/mysong.mp3"));
audioPlayer->duration(); // return 0

but all the time the function returns 0. I use the latest version Qt on Windows 8.

4

1 回答 1

0

是的,我发现了错误,它是类型转换(qint64)为了获得您需要使用“durationChanged”信号的持续时间。

//get duration in durationChanged signal.
connect(audioPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(setPositionSlider(qint64)));
//Old function
void Widget::setPositionSlider(qint64 i)
{
    ui->PositionSlider->setValue(i / duration * 100); //0 I thought it was converted into double.
}
//New function
void Widget::setPositionSlider(qint64 i)
{
    ui->PositionSlider->setValue(i / 1000);
}
于 2014-07-04T12:17:50.510 回答