Paul
Paul

Reputation: 11

QMediaPlayer QT6 How to get more accurate current file position?

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();
}

Upvotes: 1

Views: 45

Answers (0)

Related Questions