QMediaPlayer random start delay



  • Qt version: 5.0.0
    OS: Linux x86_64

    I'm writing a Guitar Hero like game (just a hobby, won't be big and professional like Guitar Hero).

    When starting the QMediaPlayer I am having ~100ms of delay.
    This is alot and causes the audio to run out of sync with the rest (read: events are not aligned with the music; thus ruining the experience).

    In the constructor I create the QMediaPlayer:
    @
    player = new QMediaPlayer(0, QMediaPlayer::LowLatency);
    player->setVolume(3); //set to default volume
    connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(playerMediaStatusChanged(QMediaPlayer::MediaStatus)));
    @

    When the user picked a 'song' I set the url (QString s) as the media:
    @
    QMediaContent content(QUrl::fromLocalFile(s));
    player->setMedia(content, 0);
    @

    When the QMediaPlayer::LoadedMedia is emitted I call the play method:
    @
    player->play();
    @

    When The QMediaPlayer::BufferedMedia is emitted I activate the rest of my application.

    I used to use the Phonon mediaplayer. It did not have the random delay and worked like a charm.
    Since Qt5 does not ship with Phonon by default, I wanted to try the built-in solution.
    I also lack the knowledge to include Phonon into my Qt5 project.

    I posted the source code on "my website":http://evilmail.net23.net/qt5_hero.tar.gz.
    You need the alter the audio path in the XML file to an existing one.

    Thanks in advance.



  • I found out that the problem was not the QMediaPlayer, it was the Timer that triggers events.
    The solution is to set the timer to be more presice:
    @
    noteTimer->setTimerType(Qt::PreciseTimer);
    @

    Problem solved :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.