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 setPosition() only reacts to big intervals of a slider
Forum Update on Monday, May 27th 2025

QMediaPlayer setPosition() only reacts to big intervals of a slider

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 2.2k Views
  • 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.
  • O Offline
    O Offline
    Oliverif
    wrote on last edited by
    #1

    When dragging a slider in order to reach a specific position in my media, the setPosition(qint64 pos) function doesn't do anything until the slider has reached some high value. Even though the input is supposed to be in milliseconds it seems like I can only jump between seconds in my video.

    I would like to scroll with milliseconds precision. Is there a way to achieve this?

    Slider connected to seek:

    connect(slider, &QSlider::sliderMoved, this, &WaveTank::seek);

    This is the seek function:

    void WaveTank::seek(int millis)
    {
    mediaPlayer->setPosition(millis);
    qDebug()<<"Slider position"<<slider->value();
    qDebug()<<"Media position"<<mediaPlayer->position();

    }

    This is the output I get:

    Slider position 0
    Media position 0

    Slider position 47
    Media position 0

    Slider position 91
    Media position 0

    Slider position 121
    Media position 0

    Slider position 149
    Media position 0

    Slider position 207
    Media position 0

    Slider position 286
    Media position 0

    Slider position 340
    Media position 0

    Slider position 396
    Media position 0

    Slider position 424
    Media position 1000

    Slider position 537
    Media position 1000

    Slider position 608
    Media position 1000

    I even tried to simply just set the position to for instance 500 by:
    mediaPlayer->setPosition(500);

    Though the mediaplayer jumps straigth to 1000.

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ?
      What OS are you on ?
      What type of video is it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Oliverif
        wrote on last edited by
        #3

        Greatly appreciate reply.
        Using Qt 5.12.2 on macOS 10.13.6 with mp4 video-format. I've also tried with the Qt MediaPlayer example which yielded the same issue. Might it be the OS?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The file format also and how the video was compressed.

          Standard frame rate is usually 25 image per second which makes one image every 40ms so unless you have a video with a higher framerate you won't be able to go below that.

          Also, depending on the format, you don't have a full image for each frame because compression etc.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Oliverif
            wrote on last edited by
            #5

            Hm, I see. The frame rate is 30. The mediaplayer jumps about 1000ms at a time when dragging the slider far enough, which means it skips 29 frames for each new setPosition() actually registered. When playing the same video in for instance vlc I can scroll with far better precision.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              VLC doesn't use the native macOS backend so it might have better control.

              Note that if it provides the control you need, there's the VLC-Qt project that provides Qt integration.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • O Offline
                O Offline
                Oliverif
                wrote on last edited by
                #7

                Got the libvlc in Qt and it works as I want, scrolling with ms precision. Thank you very much!

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You're welcome !

                  Since you got things working the way you wanted, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pvaibhav
                    wrote on last edited by
                    #9

                    Hi all, this is still an issue. I'm playing a simple uncompressed .wav file, but the QML MediaPlayer and Audio objects both react in the same way. It only seems to seek to the last multiple of 1000 ms. I've gone over the source code for qtmultimedia but can't spot anything obvious (yet).

                    Context: In our program we need to switch between multiple looping .wav files, which should resume playback from the same position as the last file. Currently they resume from the last whole-number of seconds.

                    Is there any solution?

                    Platform: macOS 10.15.6 and 10.14.x
                    Qt version: 5.15

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      IIRC, a forum user had something similar for macOS and created a patch for the macOS backend.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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