Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 2567833002: [Video] Pause videos with no audio when in the background. (Closed)
Patch Set: Pause videos without audio Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index b6a56c2cd26dce38c4fc4676e610e77460f315e6..1ab167461b5da4ef94aef05f80e29134822cbfcb 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -205,6 +205,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
opaque_(false),
playback_rate_(0.0),
paused_(true),
+ paused_when_hidden_(false),
seeking_(false),
pending_suspend_resume_cycle_(false),
ended_(false),
@@ -448,6 +449,9 @@ void WebMediaPlayerImpl::pause() {
// paused state.
paused_ = true;
+ // No longer paused because it was hidden.
+ paused_when_hidden_ = false;
+
#if defined(OS_ANDROID) // WMPI_CAST
if (isRemote()) {
cast_impl_.pause();
@@ -1336,12 +1340,19 @@ void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) {
void WebMediaPlayerImpl::OnHidden() {
DCHECK(main_task_runner_->BelongsToCurrentThread());
- if (IsBackgroundVideoTrackOptimizationEnabled())
- selectedVideoTrackChanged(nullptr);
-
if (watch_time_reporter_)
watch_time_reporter_->OnHidden();
+ if (IsBackgroundVideoTrackOptimizationEnabled()) {
+ if (ShouldPauseWhenHidden()) {
+ OnPause();
+ paused_when_hidden_ = true;
sandersd (OOO until July 31) 2017/01/06 01:44:15 Probably needs a comment to explain that the order
whywhat 2017/01/06 16:59:31 Done. Alternatively I could perhaps take the most
+ return;
+ }
+
+ selectedVideoTrackChanged(nullptr);
+ }
+
UpdatePlayState();
// Schedule suspended playing media to be paused if the user doesn't come back
@@ -1354,10 +1365,17 @@ void WebMediaPlayerImpl::OnShown() {
if (watch_time_reporter_)
watch_time_reporter_->OnShown();
- if (IsBackgroundVideoTrackOptimizationEnabled() &&
- client_->hasSelectedVideoTrack()) {
- WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId();
- selectedVideoTrackChanged(&trackId);
+ if (IsBackgroundVideoTrackOptimizationEnabled()) {
+ if (paused_when_hidden_) {
+ paused_when_hidden_ = false;
+ OnPlay();
+ return;
+ }
+
+ if (client_->hasSelectedVideoTrack()) {
+ WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId();
+ selectedVideoTrackChanged(&trackId);
+ }
}
must_suspend_ = false;
@@ -2040,4 +2058,13 @@ void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) {
client_->activateViewportIntersectionMonitoring(activate);
}
+bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const {
+#if defined(OS_ANDROID) // WMPI_CAST
+ if (isRemote())
+ return false;
+#endif // defined(OS_ANDROID) // WMPI_CAST
+
+ return hasVideo() && !hasAudio();
+}
+
} // namespace media
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698