Qt World Summit: Submit your Presentation

QTimer and Time Slider and VideoPlayer Problem

  • Hi everyone,

    I have multiple QMediaPlayers and one time slider controlling all of them.

    To make them synchronized accrding to time slider, I am using a QTimer. However, at some point Qtimer works slow, and videos runs ahead of the timer. So that, my slider shows the wrong value.

    Is there any solution for this? The value Ihave seen in the current time label is not the same as the videos (I have a clock video). For example, in the beginning both shows 1 seconds. After a tie, video is actually in 10sec, but current time label show 9sec, also this delay between them is increasing over time.

    p_video_player_timer = new QTimer(this);
        connect(p_video_player_timer, &QTimer::timeout, this, [=](){
            current_video_pos_msec += 25;
           current_time = QTime(0,0,0);

  • Lifetime Qt Champion

  • @jsulm In my current implementation I am using one of the mediaplayers as a reference point and then I am using positionchanged. Also I know that I can get the precise time with that method.

    However, my customer do not want depend on any of the videos. They want me to implement a timeslider which does not depend on any of the videos.

    I tried to implement my timer in different thread, but it still creates delay. I do not know if it is possible to have precise timer. Event draging the application window also creates a delay for a separate timer

  • Lifetime Qt Champion


    Video playback is more complex than that. You currently rarely have video files that contain as many images as you will see on screen (the classic 24 or 25 FPS). Depending on the video format and the parameters used to encode it you won't be able to be hyper precise on several of them in parallel parts because of that.

    You should consider testing VLC to see if you have better results with it.

  • @SGaist Hi,

    yes, I am currently testing it with sample videos found on the Internet

    Maybe VLC can be the alternative.

    My current solution is using a thread for the timer. To eliminate the timer's wrong timeout, I am checking the QDateTime::currentDateTime(); and the time of the previous timeout signal.
    With this, I made the synchronization between my time slider and the videos. I am just tuning the slider and all videos at the moment of play button is pressed.

    It is currently working, but I do not know if it is good or bad.

Log in to reply