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. [Qt5, QMediaPlayer]: Tiny duration black screen when the current source changed
Forum Update on Monday, May 27th 2025

[Qt5, QMediaPlayer]: Tiny duration black screen when the current source changed

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    DoHuuVi
    wrote on last edited by
    #1

    I'm writing a Video Player with Qt5::QMediaPlayer:
    int main(int argc, char argv[]) {
    QApplication a(argc, argv);
    QMediaPlaylist
    playlist = new QMediaPlaylist;
    playlist->addMedia(QUrl::fromLocalFile(".\Resources\fractal-files\A-060405V4651.WMV"));
    playlist->addMedia(QUrl::fromLocalFile(".\Resources\fractal-files\B-101604.WMV"));
    playlist->addMedia(QUrl::fromLocalFile(".\Resources\fractal-files\C-102304.WMV"));
    int current(0);
    playlist->setCurrentIndex(current++);
    QMediaPlayer* player = new QMediaPlayer;
    player->setPlaylist(playlist);
    player->setVolume(50);
    QVideoWidget* videoWidget = new QVideoWidget;
    player->setVideoOutput(videoWidget);
    videoWidget->show();
    player->play();
    QPushButton* b = new QPushButton;
    QObject::connect(b, &QPushButton::clicked, &{
    if(current > 2) current = 0;
    playlist->setCurrentIndex(current++);
    player->play();
    });
    b->show();
    return a.exec();
    }

    When the button is clicked, I will change the video source. But there are a very small duration black screen gap when switching. If I let the app switches to the next video automatic, there are no black screen gap.

    How can I make this with no black screen gap (smoothly)?
    Thank you very much!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hpollak
      wrote on last edited by
      #2

      Maybe this helps: QMediaGaplessPlaybackControl Class

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DoHuuVi
        wrote on last edited by
        #3

        Thanks hpollak! I tried:
        // QMediaGaplessPlaybackControl *gapless = qobject_cast<QMediaGaplessPlaybackControl *>(
        // player->service()->requestControl("org.qt-project.qt.mediagaplessplaybackcontrol/5.0"));
        QMediaGaplessPlaybackControl gapless = player->service()->requestControl<QMediaGaplessPlaybackControl>();
        if(!gapless) {
        qDebug() << "no QMediaGaplessPlaybackControl";
        return -1;
        }

        But the result is a null pointer. I'm using Windows 8.1. Can you give me another hint?
        Thank you very much!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DoHuuVi
          wrote on last edited by
          #4

          It seems that QMediaGaplessPlaybackControl is just an interface with no implementation. How can and what's needed to implement this interface?

          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