Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMediaPlayer random start delay
Qt 6.11 is out! See what's new in the release blog

QMediaPlayer random start delay

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pitfall
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pitfall
      wrote on last edited by
      #2

      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 :)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved