diff options
author | qinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-16 23:41:53 +0000 |
---|---|---|
committer | qinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-16 23:41:53 +0000 |
commit | 34f933929e45d28494d20788fb3950f68cb2513d (patch) | |
tree | 7b8b3559995992295b2ccaf468a20d3f5ee67bb0 | |
parent | 54dd8abe2b7a7687c82aa8bddf1c8fd2dea1b10b (diff) | |
download | chromium_src-34f933929e45d28494d20788fb3950f68cb2513d.zip chromium_src-34f933929e45d28494d20788fb3950f68cb2513d.tar.gz chromium_src-34f933929e45d28494d20788fb3950f68cb2513d.tar.bz2 |
Fix an issue that MediaController is disaled when entering fullscreen
In the old contentVideoView.java, we create the MediaController first in the openVideo() call.
Then we call updateMediaMetadata() to enable to media controller and set the metadata.
With ContentVideoViewLegacy.java, the ordering between updateMediaMetadata() and mediaController creation is reversed. That causes the controller to become disabled.
This change posts a task when RequestMediaMetadata() is called to solve the above issue, and to avoid the reentrance issue.
BUG=334635
Review URL: https://codereview.chromium.org/141243002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245376 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 25 insertions, 13 deletions
diff --git a/content/browser/android/content_video_view.cc b/content/browser/android/content_video_view.cc index 85f5719..af3067a 100644 --- a/content/browser/android/content_video_view.cc +++ b/content/browser/android/content_video_view.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/logging.h" +#include "base/message_loop/message_loop.h" #include "content/browser/android/content_view_core_impl.h" #include "content/browser/media/android/browser_media_player_manager.h" #include "content/common/android/surface_texture_peer.h" @@ -43,7 +44,8 @@ ContentVideoView* ContentVideoView::GetInstance() { ContentVideoView::ContentVideoView( BrowserMediaPlayerManager* manager) : manager_(manager), - fullscreen_state_(ENTERED) { + fullscreen_state_(ENTERED), + weak_factory_(this) { DCHECK(!g_content_video_view); j_content_video_view_ = CreateJavaObject(); g_content_video_view = this; @@ -108,8 +110,16 @@ void ContentVideoView::OnExitFullscreen() { void ContentVideoView::UpdateMediaMetadata() { JNIEnv *env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); - if (!content_video_view.is_null()) - UpdateMediaMetadata(env, content_video_view.obj()); + if (content_video_view.is_null()) + return; + + media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); + if (player && player->IsPlayerReady()) { + Java_ContentVideoView_onUpdateMediaMetadata( + env, content_video_view.obj(), player->GetVideoWidth(), + player->GetVideoHeight(), player->GetDuration().InMilliseconds(), + player->CanPause(),player->CanSeekForward(), player->CanSeekBackward()); + } } int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const { @@ -187,13 +197,11 @@ void ContentVideoView::SetSurface(JNIEnv* env, jobject obj, } } -void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { - media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); - if (player && player->IsPlayerReady()) - Java_ContentVideoView_onUpdateMediaMetadata( - env, obj, player->GetVideoWidth(), player->GetVideoHeight(), - player->GetDuration().InMilliseconds(), player->CanPause(), - player->CanSeekForward(), player->CanSeekBackward()); +void ContentVideoView::RequestMediaMetadata(JNIEnv* env, jobject obj) { + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ContentVideoView::UpdateMediaMetadata, + weak_factory_.GetWeakPtr())); } ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { diff --git a/content/browser/android/content_video_view.h b/content/browser/android/content_video_view.h index ad8945a..3c95a74 100644 --- a/content/browser/android/content_video_view.h +++ b/content/browser/android/content_video_view.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/timer/timer.h" namespace content { @@ -50,7 +51,7 @@ class ContentVideoView { int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const; int GetCurrentPosition(JNIEnv*, jobject obj) const; bool IsPlaying(JNIEnv*, jobject obj); - void UpdateMediaMetadata(JNIEnv*, jobject obj); + void RequestMediaMetadata(JNIEnv*, jobject obj); // Called when the Java fullscreen view is destroyed. If // |release_media_player| is true, |manager_| needs to release the player @@ -107,6 +108,9 @@ class ContentVideoView { RESUME } fullscreen_state_; + // Weak pointer for posting tasks. + base::WeakPtrFactory<ContentVideoView> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(ContentVideoView); }; diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java index 8ad008b8..a1c2f14 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java @@ -286,7 +286,7 @@ public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callb if (mSurfaceHolder != null) { mCurrentState = STATE_IDLE; if (mNativeContentVideoView != 0) { - nativeUpdateMediaMetadata(mNativeContentVideoView); + nativeRequestMediaMetadata(mNativeContentVideoView); nativeSetSurface(mNativeContentVideoView, mSurfaceHolder.getSurface()); } @@ -429,7 +429,7 @@ public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callb boolean relaseMediaPlayer); private native int nativeGetCurrentPosition(long nativeContentVideoView); private native int nativeGetDurationInMilliSeconds(long nativeContentVideoView); - private native void nativeUpdateMediaMetadata(long nativeContentVideoView); + private native void nativeRequestMediaMetadata(long nativeContentVideoView); private native int nativeGetVideoWidth(long nativeContentVideoView); private native int nativeGetVideoHeight(long nativeContentVideoView); private native boolean nativeIsPlaying(long nativeContentVideoView); |