Important: Please read the Qt Code of Conduct -

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

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

    Though the mediaplayer jumps straigth to 1000.

    Thanks in advance.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

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

  • 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?

  • Lifetime Qt Champion

    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.

  • 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.

  • Lifetime Qt Champion

    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.

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

  • Lifetime Qt Champion

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

  • 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

  • Lifetime Qt Champion

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

Log in to reply