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

Unified Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 2490783002: Refactor WebMediaPlayerDelegate interface. (Closed)
Patch Set: Update WMPA properly. Created 4 years 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
Index: content/renderer/media/android/webmediaplayer_android.cc
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc
index 6ab41032e752503f28c5e2cde2e926182d5d1645..d63b830eede7f20ea22e6c5c52894940bca00b4d 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -182,8 +182,10 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
DCHECK(main_thread_checker_.CalledOnValidThread());
- if (delegate_)
+ if (delegate_) {
delegate_id_ = delegate_->AddObserver(this);
+ delegate_->SetIdle(delegate_id_, true);
+ }
player_id_ = player_manager_->RegisterMediaPlayer(this);
@@ -295,8 +297,9 @@ void WebMediaPlayerAndroid::play() {
bool can_video_play_in_background =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableMediaSuspend) ||
- (IsBackgroundVideoCandidate() &&
- delegate_ && delegate_->IsPlayingBackgroundVideo());
+ (IsBackgroundVideoCandidate() && delegate_ &&
whywhat 2016/12/12 18:11:23 nit: isBackgroundVideoCandidate will already check
sandersd (OOO until July 31) 2017/01/05 23:12:21 Done.
+ delegate_->IsFrameHidden() && !delegate_->IsFrameClosed() &&
+ delegate_->IsBackgroundVideoPlaybackAllowed());
if (!can_video_play_in_background) {
is_play_pending_ = true;
return;
@@ -823,8 +826,10 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
// If we're paused after we receive metadata for the first time, tell the
// delegate we can now be safely suspended due to inactivity if a subsequent
// play event does not occur.
- if (paused() && delegate_)
- delegate_->DidPause(delegate_id_, false);
+ if (paused() && delegate_) {
+ delegate_->DidPause(delegate_id_);
+ delegate_->SetIdle(delegate_id_, true);
+ }
}
}
@@ -1199,19 +1204,28 @@ void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) {
// be known at this point -- there are no video only containers, so only
// send audio if we know for sure its audio. The browser side player will
// fill in the correct value later for media sessions.
- delegate_->DidPlay(delegate_id_, hasVideo(), !hasVideo(), isRemote(),
- media::DurationToMediaContentType(duration_));
+ if (isRemote()) {
+ delegate_->PlayerGone(delegate_id_);
+ } else {
+ delegate_->DidPlay(delegate_id_, !hasVideo(), hasVideo(),
+ media::DurationToMediaContentType(duration_));
+ }
+ delegate_->SetIdle(delegate_id_, false);
} else {
// Even if OnPlaybackComplete() has not been called yet, Blink may have
// already fired the ended event based on current time relative to
// duration -- so we need to check both possibilities here.
- delegate_->DidPause(delegate_id_,
- playback_completed_ || currentTime() >= duration());
+ if (playback_completed_ || currentTime() >= duration()) {
+ delegate_->PlayerGone(delegate_id_);
+ } else {
+ delegate_->DidPause(delegate_id_);
+ }
+ delegate_->SetIdle(delegate_id_, true);
}
}
}
-void WebMediaPlayerAndroid::OnHidden() {
+void WebMediaPlayerAndroid::OnFrameHidden() {
// Pause audible video preserving its session.
if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) {
Pause(false);
@@ -1219,24 +1233,27 @@ void WebMediaPlayerAndroid::OnHidden() {
return;
}
- OnSuspendRequested(false);
+ OnIdleTimeout();
+}
+
+void WebMediaPlayerAndroid::OnFrameClosed() {
+ SuspendAndReleaseResources();
}
-void WebMediaPlayerAndroid::OnShown() {
+void WebMediaPlayerAndroid::OnFrameShown() {
if (is_play_pending_)
play();
}
-bool WebMediaPlayerAndroid::OnSuspendRequested(bool must_suspend) {
- if (!must_suspend &&
- base::CommandLine::ForCurrentProcess()->HasSwitch(
+bool WebMediaPlayerAndroid::OnIdleTimeout() {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableMediaSuspend)) {
return true;
}
// If we're idle or playing video, pause and release resources; audio only
- // players are allowed to continue unless indicated otherwise by the call.
- if (must_suspend || (paused() && playback_completed_) ||
+ // players are allowed to continue.
+ if ((paused() && playback_completed_) ||
(hasVideo() && !IsBackgroundVideoCandidate())) {
SuspendAndReleaseResources();
}
@@ -1322,7 +1339,8 @@ bool WebMediaPlayerAndroid::IsBackgroundVideoCandidate() const {
}
return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) &&
- hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden();
+ hasAudio() && !isRemote() && delegate_ && delegate_->IsFrameHidden() &&
+ !delegate_->IsFrameClosed();
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698