From 321e4ffe9c1c5babce0ad8fc4a5cc294f42c7381 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 8 Apr 2019 14:34:31 +0400 Subject: [PATCH] Don't auto-resume video when seeking. --- .../media/view/media_view_overlay_widget.cpp | 24 +++++++++++++------ .../media/view/media_view_overlay_widget.h | 1 - 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index c4c9c485c0..c865716302 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -169,6 +169,8 @@ struct OverlayWidget::Streamed { base::Timer timer; QImage frameForDirectPaint; + bool withSound = false; + bool pausedBySeek = false; bool resumeOnCallEnd = false; }; @@ -2007,6 +2009,10 @@ void OverlayWidget::createStreamingObjects() { this, static_cast(this), [=] { waitingAnimationCallback(); }); + _streamed->withSound = _doc->isAudioFile() + || _doc->isVideoFile() + || _doc->isVoiceMessage() + || _doc->isVideoMessage(); if (videoIsGifv()) { _streamed->controls.hide(); @@ -2261,6 +2267,7 @@ void OverlayWidget::playbackPauseResume() { void OverlayWidget::restartAtSeekPosition(crl::time position) { Expects(_streamed != nullptr); + Expects(_doc != nullptr); if (videoShown()) { _streamed->info.video.cover = videoFrame(); @@ -2270,13 +2277,9 @@ void OverlayWidget::restartAtSeekPosition(crl::time position) { auto options = Streaming::PlaybackOptions(); options.position = position; options.audioId = AudioMsgId(_doc, _msgid); - if (_doc->isAnimation() - || options.audioId.type() == AudioMsgId::Type::Unknown) { + if (!_streamed->withSound) { options.mode = Streaming::Mode::Video; options.loop = true; - _streamingPauseMusic = false; - } else { - _streamingPauseMusic = true; } _streamed->player.play(options); if (_streamingStartPaused) { @@ -2284,6 +2287,7 @@ void OverlayWidget::restartAtSeekPosition(crl::time position) { } else { playbackPauseMusic(); } + _streamed->pausedBySeek = false; _streamed->info.audio.state.position = _streamed->info.video.state.position @@ -2296,12 +2300,16 @@ void OverlayWidget::playbackControlsSeekProgress(crl::time position) { Expects(_streamed != nullptr); if (!_streamed->player.paused() && !_streamed->player.finished()) { + _streamed->pausedBySeek = true; playbackControlsPause(); } } void OverlayWidget::playbackControlsSeekFinished(crl::time position) { - _streamingStartPaused = false; + Expects(_streamed != nullptr); + + _streamingStartPaused = !_streamed->pausedBySeek + && !_streamed->player.finished(); restartAtSeekPosition(position); } @@ -2359,7 +2367,9 @@ void OverlayWidget::playbackResumeOnCall() { } void OverlayWidget::playbackPauseMusic() { - if (!_streamingPauseMusic) { + Expects(_streamed != nullptr); + + if (!_streamed->withSound) { return; } Player::instance()->pause(AudioMsgId::Type::Voice); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 8b957f4d47..6fd4460f6a 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -338,7 +338,6 @@ private: QString _headerText; bool _streamingStartPaused = false; - bool _streamingPauseMusic = false; bool _fullScreenVideo = false; int _fullScreenZoomCache = 0;