c++ - QMediaPlayer QT6 How to get more accurate current file position? - Stack Overflow

I try to get current time with player->position(), but in the debug() I see not all frames, even I s

I try to get current time with player->position(), but in the debug() I see not all frames, even I set timer update speed to 1 ms.

Debug output: 1828 1828 1828 1880 1880 1880 1933 1933

Seems that QMediaPlayer::positionChanged updates about 50ms at time.

How I can get more accurate frame counter?

Example code:

QMediaPlayer *player;
QTimer *timer;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    player = new QMediaPlayer(this);
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &MainWindow::updateTime);
}

void MainWindow::on_pushButton_clicked()
{
    QAudioOutput *audioOutput = new QAudioOutput(this);
    player->setAudioOutput(audioOutput);
    player->setSource(QUrl::fromLocalFile("test.mp3"));
    player->play();
    timer->start(10);
}

void MainWindow::updateTime()
{
    qDebug() << player->position();
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745515234a4630954.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信