Pause all media if a call is created.

Pause video, voice messages, songs and stop video messages.
This commit is contained in:
John Preston 2017-05-12 20:44:18 +03:00
parent 040ee90aec
commit 565b56fb5f
9 changed files with 59 additions and 9 deletions

View File

@ -2645,15 +2645,28 @@ namespace {
void stopGifItems() { void stopGifItems() {
if (!::gifItems.isEmpty()) { if (!::gifItems.isEmpty()) {
GifItems gifs = ::gifItems; auto gifs = ::gifItems;
for (GifItems::const_iterator i = gifs.cbegin(), e = gifs.cend(); i != e; ++i) { for_const (auto item, gifs) {
if (HistoryMedia *media = i.value()->getMedia()) { if (auto media = item->getMedia()) {
media->stopInline(); 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) { QString phoneFromSharedContact(int32 userId) {
auto i = ::sharedContactItems.constFind(userId); auto i = ::sharedContactItems.constFind(userId);
if (i != ::sharedContactItems.cend() && !i->isEmpty()) { if (i != ::sharedContactItems.cend() && !i->isEmpty()) {

View File

@ -268,6 +268,7 @@ namespace App {
void regGifItem(Media::Clip::Reader *reader, HistoryItem *item); void regGifItem(Media::Clip::Reader *reader, HistoryItem *item);
void unregGifItem(Media::Clip::Reader *reader); void unregGifItem(Media::Clip::Reader *reader);
void stopRoundVideoPlayback();
void stopGifItems(); void stopGifItems();
void regMuted(PeerData *peer, int32 changeIn); void regMuted(PeerData *peer, int32 changeIn);

View File

@ -113,6 +113,9 @@ public:
} }
virtual void stopInline() { virtual void stopInline() {
} }
virtual bool isRoundVideoPlaying() const {
return false;
}
virtual void attachToParent() { virtual void attachToParent() {
} }

View File

@ -2304,8 +2304,12 @@ bool HistoryGif::playInline(bool autoplay) {
return true; return true;
} }
bool HistoryGif::isRoundVideoPlaying() const {
return (_gif && _gif->mode() == Media::Clip::Reader::Mode::Video);
}
void HistoryGif::stopInline() { void HistoryGif::stopInline() {
if (_gif && _gif->mode() == Media::Clip::Reader::Mode::Video) { if (isRoundVideoPlaying()) {
App::wnd()->controller()->disableGifPauseReason(Window::GifPauseReason::RoundPlaying); App::wnd()->controller()->disableGifPauseReason(Window::GifPauseReason::RoundPlaying);
} }
clearClipReader(); clearClipReader();

View File

@ -499,6 +499,7 @@ public:
bool playInline(bool autoplay) override; bool playInline(bool autoplay) override;
void stopInline() override; void stopInline() override;
bool isRoundVideoPlaying() const override;
void attachToParent() override; void attachToParent() override;
void detachFromParent() override; void detachFromParent() override;

View File

@ -1644,6 +1644,7 @@ void MainWidget::setCurrentCall(Calls::Call *call) {
destroyCallTopBar(); destroyCallTopBar();
} }
}); });
App::stopRoundVideoPlayback();
} else { } else {
destroyCallTopBar(); destroyCallTopBar();
} }

View File

@ -23,6 +23,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "media/media_audio.h" #include "media/media_audio.h"
#include "media/media_audio_capture.h" #include "media/media_audio_capture.h"
#include "observer_peer.h" #include "observer_peer.h"
#include "messenger.h"
#include "auth_session.h"
#include "calls/calls_instance.h"
namespace Media { namespace Media {
namespace Player { namespace Player {
@ -59,6 +62,22 @@ Instance::Instance() {
handleLogout(); 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) { void Instance::notifyPeerUpdated(const Notify::PeerUpdate &update) {

View File

@ -128,7 +128,9 @@ Widget::Widget(QWidget *parent) : TWidget(parent)
handlePlaylistUpdate(); handlePlaylistUpdate();
}); });
subscribe(instance()->updatedNotifier(), [this](const TrackState &state) { subscribe(instance()->updatedNotifier(), [this](const TrackState &state) {
if (state.id.type() == AudioMsgId::Type::Song) {
handleSongUpdate(state); handleSongUpdate(state);
}
}); });
subscribe(instance()->songChangedNotifier(), [this] { subscribe(instance()->songChangedNotifier(), [this] {
handleSongChange(); handleSongChange();

View File

@ -39,6 +39,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "auth_session.h" #include "auth_session.h"
#include "messenger.h" #include "messenger.h"
#include "storage/file_download.h" #include "storage/file_download.h"
#include "calls/calls_instance.h"
namespace { namespace {
@ -90,19 +91,24 @@ MediaView::MediaView(QWidget*) : TWidget(nullptr)
connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int)));
// While we have one mediaview for all authsessions we have to do this. // While we have one mediaview for all authsessions we have to do this.
auto subscribeToDownloadFinished = [this] { auto handleAuthSessionChange = [this] {
if (AuthSession::Exists()) { if (AuthSession::Exists()) {
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] {
if (!isHidden()) { if (!isHidden()) {
updateControls(); updateControls();
} }
}); });
subscribe(AuthSession::Current().calls().currentCallChanged(), [this](Calls::Call *call) {
if (call && _clipController && !_videoPaused) {
onVideoPauseResume();
}
});
} }
}; };
subscribe(Messenger::Instance().authSessionChanged(), [subscribeToDownloadFinished] { subscribe(Messenger::Instance().authSessionChanged(), [handleAuthSessionChange] {
subscribeToDownloadFinished(); handleAuthSessionChange();
}); });
subscribeToDownloadFinished(); handleAuthSessionChange();
auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged; auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) { subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {