diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 8bd5a8acbb..689a9babd9 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -2645,15 +2645,28 @@ namespace { void stopGifItems() { if (!::gifItems.isEmpty()) { - GifItems gifs = ::gifItems; - for (GifItems::const_iterator i = gifs.cbegin(), e = gifs.cend(); i != e; ++i) { - if (HistoryMedia *media = i.value()->getMedia()) { + auto gifs = ::gifItems; + for_const (auto item, gifs) { + if (auto media = item->getMedia()) { media->stopInline(); } } } } + void stopRoundVideoPlayback() { + if (!::gifItems.isEmpty()) { + auto gifs = ::gifItems; + for_const (auto item, gifs) { + if (auto media = item->getMedia()) { + if (media->isRoundVideoPlaying()) { + media->stopInline(); + } + } + } + } + } + QString phoneFromSharedContact(int32 userId) { auto i = ::sharedContactItems.constFind(userId); if (i != ::sharedContactItems.cend() && !i->isEmpty()) { diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index a656e40610..bbc75ef495 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -268,6 +268,7 @@ namespace App { void regGifItem(Media::Clip::Reader *reader, HistoryItem *item); void unregGifItem(Media::Clip::Reader *reader); + void stopRoundVideoPlayback(); void stopGifItems(); void regMuted(PeerData *peer, int32 changeIn); diff --git a/Telegram/SourceFiles/history/history_media.h b/Telegram/SourceFiles/history/history_media.h index 7b85cf0a91..05689edad8 100644 --- a/Telegram/SourceFiles/history/history_media.h +++ b/Telegram/SourceFiles/history/history_media.h @@ -113,6 +113,9 @@ public: } virtual void stopInline() { } + virtual bool isRoundVideoPlaying() const { + return false; + } virtual void attachToParent() { } diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index bdd0ad063c..aa152aee29 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -2304,8 +2304,12 @@ bool HistoryGif::playInline(bool autoplay) { return true; } +bool HistoryGif::isRoundVideoPlaying() const { + return (_gif && _gif->mode() == Media::Clip::Reader::Mode::Video); +} + void HistoryGif::stopInline() { - if (_gif && _gif->mode() == Media::Clip::Reader::Mode::Video) { + if (isRoundVideoPlaying()) { App::wnd()->controller()->disableGifPauseReason(Window::GifPauseReason::RoundPlaying); } clearClipReader(); diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index f0b4e55b0a..fbee130af0 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -499,6 +499,7 @@ public: bool playInline(bool autoplay) override; void stopInline() override; + bool isRoundVideoPlaying() const override; void attachToParent() override; void detachFromParent() override; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 82fbb858ba..069f11b659 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1644,6 +1644,7 @@ void MainWidget::setCurrentCall(Calls::Call *call) { destroyCallTopBar(); } }); + App::stopRoundVideoPlayback(); } else { destroyCallTopBar(); } diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index 2e520cc027..57403c0250 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -23,6 +23,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "media/media_audio.h" #include "media/media_audio_capture.h" #include "observer_peer.h" +#include "messenger.h" +#include "auth_session.h" +#include "calls/calls_instance.h" namespace Media { namespace Player { @@ -59,6 +62,22 @@ Instance::Instance() { handleLogout(); } }); + + // While we have one Media::Player::Instance for all authsessions we have to do this. + auto handleAuthSessionChange = [this] { + if (AuthSession::Exists()) { + subscribe(AuthSession::Current().calls().currentCallChanged(), [this](Calls::Call *call) { + if (call) { + pause(AudioMsgId::Type::Voice); + pause(AudioMsgId::Type::Song); + } + }); + } + }; + subscribe(Messenger::Instance().authSessionChanged(), [handleAuthSessionChange] { + handleAuthSessionChange(); + }); + handleAuthSessionChange(); } void Instance::notifyPeerUpdated(const Notify::PeerUpdate &update) { diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 3676474284..6ae1808cb4 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -128,7 +128,9 @@ Widget::Widget(QWidget *parent) : TWidget(parent) handlePlaylistUpdate(); }); subscribe(instance()->updatedNotifier(), [this](const TrackState &state) { - handleSongUpdate(state); + if (state.id.type() == AudioMsgId::Type::Song) { + handleSongUpdate(state); + } }); subscribe(instance()->songChangedNotifier(), [this] { handleSongChange(); diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 8a0cd1cfd3..b15042be8b 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -39,6 +39,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "auth_session.h" #include "messenger.h" #include "storage/file_download.h" +#include "calls/calls_instance.h" namespace { @@ -90,19 +91,24 @@ MediaView::MediaView(QWidget*) : TWidget(nullptr) connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); // While we have one mediaview for all authsessions we have to do this. - auto subscribeToDownloadFinished = [this] { + auto handleAuthSessionChange = [this] { if (AuthSession::Exists()) { subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { if (!isHidden()) { updateControls(); } }); + subscribe(AuthSession::Current().calls().currentCallChanged(), [this](Calls::Call *call) { + if (call && _clipController && !_videoPaused) { + onVideoPauseResume(); + } + }); } }; - subscribe(Messenger::Instance().authSessionChanged(), [subscribeToDownloadFinished] { - subscribeToDownloadFinished(); + subscribe(Messenger::Instance().authSessionChanged(), [handleAuthSessionChange] { + handleAuthSessionChange(); }); - subscribeToDownloadFinished(); + handleAuthSessionChange(); auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged; subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {