Skip to content

Commit

Permalink
fix: viewer crashes when switching between video and non-video assets
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomiguelino committed Oct 1, 2024
1 parent 2b01ba2 commit d3a2c9a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions webview/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ void MainWindow::loadVideo(const QString &uri, unsigned int durationInSecs)
{
ready = false;
player->setMedia(QUrl::fromLocalFile(uri));
this->setCentralWidget(videoWidget);

view->hide();
videoWidget->setFullScreen(true);
videoWidget->show();

player->play();

// Convert duration from seconds to milliseconds.
unsigned int additionalDurationInMs = 500; // This prevents the video for being stopped too early.
unsigned int additionalDurationInMs = 1000; // This prevents the video for being stopped too early.
unsigned int durationInMs = durationInSecs * 1000 + additionalDurationInMs;

// @TODO: Use the state() method instead to check if the video is still playing.
// At the moment, state() returns QMediaPlayer::StoppedState even if the video is still playing.
QTimer::singleShot(durationInMs, this, [=](){
player->stop();
ready = true;

videoWidget->hide();
view->show();
});
}
}
Expand Down

0 comments on commit d3a2c9a

Please sign in to comment.