Commit 34f93392 authored by qinmin@chromium.org's avatar qinmin@chromium.org

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
parent 54dd8abe
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "content/browser/android/content_view_core_impl.h" #include "content/browser/android/content_view_core_impl.h"
#include "content/browser/media/android/browser_media_player_manager.h" #include "content/browser/media/android/browser_media_player_manager.h"
#include "content/common/android/surface_texture_peer.h" #include "content/common/android/surface_texture_peer.h"
...@@ -43,7 +44,8 @@ ContentVideoView* ContentVideoView::GetInstance() { ...@@ -43,7 +44,8 @@ ContentVideoView* ContentVideoView::GetInstance() {
ContentVideoView::ContentVideoView( ContentVideoView::ContentVideoView(
BrowserMediaPlayerManager* manager) BrowserMediaPlayerManager* manager)
: manager_(manager), : manager_(manager),
fullscreen_state_(ENTERED) { fullscreen_state_(ENTERED),
weak_factory_(this) {
DCHECK(!g_content_video_view); DCHECK(!g_content_video_view);
j_content_video_view_ = CreateJavaObject(); j_content_video_view_ = CreateJavaObject();
g_content_video_view = this; g_content_video_view = this;
...@@ -108,8 +110,16 @@ void ContentVideoView::OnExitFullscreen() { ...@@ -108,8 +110,16 @@ void ContentVideoView::OnExitFullscreen() {
void ContentVideoView::UpdateMediaMetadata() { void ContentVideoView::UpdateMediaMetadata() {
JNIEnv *env = AttachCurrentThread(); JNIEnv *env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
if (!content_video_view.is_null()) if (content_video_view.is_null())
UpdateMediaMetadata(env, content_video_view.obj()); 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 { int ContentVideoView::GetVideoWidth(JNIEnv*, jobject obj) const {
...@@ -187,13 +197,11 @@ void ContentVideoView::SetSurface(JNIEnv* env, jobject obj, ...@@ -187,13 +197,11 @@ void ContentVideoView::SetSurface(JNIEnv* env, jobject obj,
} }
} }
void ContentVideoView::UpdateMediaMetadata(JNIEnv* env, jobject obj) { void ContentVideoView::RequestMediaMetadata(JNIEnv* env, jobject obj) {
media::MediaPlayerAndroid* player = manager_->GetFullscreenPlayer(); base::MessageLoop::current()->PostTask(
if (player && player->IsPlayerReady()) FROM_HERE,
Java_ContentVideoView_onUpdateMediaMetadata( base::Bind(&ContentVideoView::UpdateMediaMetadata,
env, obj, player->GetVideoWidth(), player->GetVideoHeight(), weak_factory_.GetWeakPtr()));
player->GetDuration().InMilliseconds(), player->CanPause(),
player->CanSeekForward(), player->CanSeekBackward());
} }
ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) { ScopedJavaLocalRef<jobject> ContentVideoView::GetJavaObject(JNIEnv* env) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
namespace content { namespace content {
...@@ -50,7 +51,7 @@ class ContentVideoView { ...@@ -50,7 +51,7 @@ class ContentVideoView {
int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const; int GetDurationInMilliSeconds(JNIEnv*, jobject obj) const;
int GetCurrentPosition(JNIEnv*, jobject obj) const; int GetCurrentPosition(JNIEnv*, jobject obj) const;
bool IsPlaying(JNIEnv*, jobject obj); bool IsPlaying(JNIEnv*, jobject obj);
void UpdateMediaMetadata(JNIEnv*, jobject obj); void RequestMediaMetadata(JNIEnv*, jobject obj);
// Called when the Java fullscreen view is destroyed. If // Called when the Java fullscreen view is destroyed. If
// |release_media_player| is true, |manager_| needs to release the player // |release_media_player| is true, |manager_| needs to release the player
...@@ -107,6 +108,9 @@ class ContentVideoView { ...@@ -107,6 +108,9 @@ class ContentVideoView {
RESUME RESUME
} fullscreen_state_; } fullscreen_state_;
// Weak pointer for posting tasks.
base::WeakPtrFactory<ContentVideoView> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ContentVideoView); DISALLOW_COPY_AND_ASSIGN(ContentVideoView);
}; };
......
...@@ -286,7 +286,7 @@ public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callb ...@@ -286,7 +286,7 @@ public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callb
if (mSurfaceHolder != null) { if (mSurfaceHolder != null) {
mCurrentState = STATE_IDLE; mCurrentState = STATE_IDLE;
if (mNativeContentVideoView != 0) { if (mNativeContentVideoView != 0) {
nativeUpdateMediaMetadata(mNativeContentVideoView); nativeRequestMediaMetadata(mNativeContentVideoView);
nativeSetSurface(mNativeContentVideoView, nativeSetSurface(mNativeContentVideoView,
mSurfaceHolder.getSurface()); mSurfaceHolder.getSurface());
} }
...@@ -429,7 +429,7 @@ public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callb ...@@ -429,7 +429,7 @@ public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callb
boolean relaseMediaPlayer); boolean relaseMediaPlayer);
private native int nativeGetCurrentPosition(long nativeContentVideoView); private native int nativeGetCurrentPosition(long nativeContentVideoView);
private native int nativeGetDurationInMilliSeconds(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 nativeGetVideoWidth(long nativeContentVideoView);
private native int nativeGetVideoHeight(long nativeContentVideoView); private native int nativeGetVideoHeight(long nativeContentVideoView);
private native boolean nativeIsPlaying(long nativeContentVideoView); private native boolean nativeIsPlaying(long nativeContentVideoView);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment