Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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);
    p_video_player_timer->setInterval(25);
        connect(p_video_player_timer, &QTimer::timeout, this, [=](){
            current_video_pos_msec += 25;
            p_time_slider->blockSignals(true);
            p_time_slider->setValue(current_video_pos_msec);
            p_time_slider->blockSignals(false);
           current_time = QTime(0,0,0);
            current_time.addMSecs(current_video_pos_msec);
     p_current_time_label->setText(current_time.toString(m_TIME_FORMAT));
        });
    

  • 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

    Hi,

    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