From cfcc1b1ce7e0e691cab7fc48e53082e0861f23a8 Mon Sep 17 00:00:00 2001 From: Hermesis Date: Sun, 26 Sep 2021 08:41:55 +0400 Subject: [PATCH] Control video in fullscreen mode using arrows and numbers --- .../media/view/media_view_overlay_widget.cpp | 32 +++++++++++++++++++ .../media/view/media_view_overlay_widget.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 041a2e9cbe..ceb12e3157 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -94,6 +94,7 @@ constexpr auto kPreloadCount = 3; constexpr auto kMaxZoomLevel = 7; // x8 constexpr auto kZoomToScreenLevel = 1024; constexpr auto kOverlayLoaderPriority = 2; +constexpr auto kSeekTimeMs = 5 * crl::time(1000); // macOS OpenGL renderer fails to render larger texture // even though it reports that max texture size is 16384. @@ -3002,6 +3003,23 @@ void OverlayWidget::playbackPauseResume() { } } +void OverlayWidget::seekRelativeTime(crl::time time) { + Expects(_streamed != nullptr); + + const auto newTime = std::clamp( + _streamed->instance.info().video.state.position + time, + crl::time(0), + _streamed->instance.info().video.state.duration); + restartAtSeekPosition(newTime); +} + +void OverlayWidget::restartAtProgress(float64 progress) { + Expects(_streamed != nullptr); + + restartAtSeekPosition(_streamed->instance.info().video.state.duration + * std::clamp(progress, 0., 1.)); +} + void OverlayWidget::restartAtSeekPosition(crl::time position) { Expects(_streamed != nullptr); @@ -3737,7 +3755,21 @@ void OverlayWidget::handleKeyPress(not_null e) { } else if (_fullScreenVideo) { if (key == Qt::Key_Escape) { playbackToggleFullScreen(); + } else if (key == Qt::Key_0) { + activateControls(); + restartAtSeekPosition(0); + } else if (key >= Qt::Key_1 && key <= Qt::Key_9) { + activateControls(); + const auto index = int(key - Qt::Key_0); + restartAtProgress(index / 10.0); + } else if (key == Qt::Key_Left) { + activateControls(); + seekRelativeTime(-kSeekTimeMs); + } else if (key == Qt::Key_Right) { + activateControls(); + seekRelativeTime(kSeekTimeMs); } + return; } } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index af83a5f9b2..e61460b56e 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -294,6 +294,8 @@ private: void setZoomLevel(int newZoom, bool force = false); void updatePlaybackState(); + void seekRelativeTime(crl::time time); + void restartAtProgress(float64 progress); void restartAtSeekPosition(crl::time position); void refreshClipControllerGeometry();