Pause all media if a call is created.
Pause video, voice messages, songs and stop video messages.
This commit is contained in:
		
							parent
							
								
									040ee90aec
								
							
						
					
					
						commit
						565b56fb5f
					
				
					 9 changed files with 59 additions and 9 deletions
				
			
		|  | @ -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()) { | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -113,6 +113,9 @@ public: | |||
| 	} | ||||
| 	virtual void stopInline() { | ||||
| 	} | ||||
| 	virtual bool isRoundVideoPlaying() const { | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	virtual void attachToParent() { | ||||
| 	} | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -499,6 +499,7 @@ public: | |||
| 
 | ||||
| 	bool playInline(bool autoplay) override; | ||||
| 	void stopInline() override; | ||||
| 	bool isRoundVideoPlaying() const override; | ||||
| 
 | ||||
| 	void attachToParent() override; | ||||
| 	void detachFromParent() override; | ||||
|  |  | |||
|  | @ -1644,6 +1644,7 @@ void MainWidget::setCurrentCall(Calls::Call *call) { | |||
| 				destroyCallTopBar(); | ||||
| 			} | ||||
| 		}); | ||||
| 		App::stopRoundVideoPlayback(); | ||||
| 	} else { | ||||
| 		destroyCallTopBar(); | ||||
| 	} | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
|  | @ -128,7 +128,9 @@ Widget::Widget(QWidget *parent) : TWidget(parent) | |||
| 		handlePlaylistUpdate(); | ||||
| 	}); | ||||
| 	subscribe(instance()->updatedNotifier(), [this](const TrackState &state) { | ||||
| 		if (state.id.type() == AudioMsgId::Type::Song) { | ||||
| 			handleSongUpdate(state); | ||||
| 		} | ||||
| 	}); | ||||
| 	subscribe(instance()->songChangedNotifier(), [this] { | ||||
| 		handleSongChange(); | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston