Index: content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java |
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 47a42a4a2dd534643f41a09328a021e11c9ad13d..67e8f0bf1b57f879a2255079ad3582c2fb35ccbc 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 |
@@ -88,7 +88,6 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
private boolean mCanPause; |
private boolean mCanSeekBack; |
private boolean mCanSeekForward; |
- private boolean mHasMediaMetadata = false; |
// Native pointer to C++ ContentVideoView object. |
private int mNativeContentVideoView = 0; |
@@ -103,14 +102,11 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
static String mErrorTitle; |
// This view will contain the video. |
- private static VideoSurfaceView sVideoSurfaceView; |
+ private VideoSurfaceView mVideoSurfaceView; |
private Surface mSurface = null; |
private static Activity sChromeActivity; |
- private static FrameLayout sRootLayout; |
- private static ViewGroup sContentContainer; |
- private static ViewGroup sControlContainer; |
// There are can be at most 1 fullscreen video |
// TODO(qinmin): will change this once we move the creation of this class |
@@ -138,6 +134,13 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
} |
} |
+ private Runnable mExitFullscreenRunnable = new Runnable() { |
+ @Override |
+ public void run() { |
+ destroyContentVideoView(); |
+ } |
+ }; |
+ |
public ContentVideoView(Context context) { |
this(context, 0); |
} |
@@ -150,7 +153,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
mNativeContentVideoView = nativeContentVideoView; |
mCurrentBufferPercentage = 0; |
- sVideoSurfaceView = new VideoSurfaceView(context); |
+ mVideoSurfaceView = new VideoSurfaceView(context); |
mCurrentState = isPlaying() ? STATE_PLAYING : STATE_PAUSED; |
} |
@@ -171,18 +174,19 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
} |
void showContentVideoView() { |
- this.addView(sVideoSurfaceView, |
+ this.addView(mVideoSurfaceView, |
new FrameLayout.LayoutParams( |
ViewGroup.LayoutParams.WRAP_CONTENT, |
ViewGroup.LayoutParams.WRAP_CONTENT, |
Gravity.CENTER)); |
- sVideoSurfaceView.setOnKeyListener(this); |
- sVideoSurfaceView.setOnTouchListener(this); |
- sVideoSurfaceView.getHolder().addCallback(this); |
- sVideoSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); |
- sVideoSurfaceView.setFocusable(true); |
- sVideoSurfaceView.setFocusableInTouchMode(true); |
- sVideoSurfaceView.requestFocus(); |
+ mVideoSurfaceView.setZOrderMediaOverlay(true); |
+ mVideoSurfaceView.setOnKeyListener(this); |
+ mVideoSurfaceView.setOnTouchListener(this); |
+ mVideoSurfaceView.getHolder().addCallback(this); |
+ mVideoSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); |
+ mVideoSurfaceView.setFocusable(true); |
+ mVideoSurfaceView.setFocusableInTouchMode(true); |
+ mVideoSurfaceView.requestFocus(); |
} |
@CalledByNative |
@@ -235,7 +239,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
mVideoWidth = width; |
mVideoHeight = height; |
if (mVideoWidth != 0 && mVideoHeight != 0) { |
- sVideoSurfaceView.getHolder().setFixedSize(mVideoWidth, mVideoHeight); |
+ mVideoSurfaceView.getHolder().setFixedSize(mVideoWidth, mVideoHeight); |
} |
} |
@@ -261,7 +265,6 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
mCanPause = canPause; |
mCanSeekBack = canSeekBack; |
mCanSeekForward = canSeekForward; |
- mHasMediaMetadata = true; |
if (mMediaController != null) { |
mMediaController.setEnabled(true); |
@@ -278,19 +281,19 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
public void destroyNativeView() { |
if (mNativeContentVideoView != 0) { |
mNativeContentVideoView = 0; |
+ destroyContentVideoView(); |
} |
} |
@Override |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
- sVideoSurfaceView.setFocusable(true); |
- sVideoSurfaceView.setFocusableInTouchMode(true); |
+ mVideoSurfaceView.setFocusable(true); |
+ mVideoSurfaceView.setFocusableInTouchMode(true); |
if (isInPlaybackState() && mMediaController != null) { |
if (mMediaController.isShowing()) { |
// ensure the controller will get repositioned later |
mMediaController.hide(); |
} |
- mMediaController.show(); |
} |
} |
@@ -304,13 +307,11 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
public void surfaceDestroyed(SurfaceHolder holder) { |
mSurfaceHolder = null; |
if (mNativeContentVideoView != 0) { |
- nativeDestroyContentVideoView(mNativeContentVideoView, true); |
- destroyNativeView(); |
- } |
- if (mMediaController != null) { |
- mMediaController.hide(); |
- mMediaController = null; |
+ nativeExitFullscreen(mNativeContentVideoView, true); |
+ mNativeContentVideoView = 0; |
+ post(mExitFullscreenRunnable); |
} |
+ removeMediaController(); |
} |
public void setMediaController(MediaController controller) { |
@@ -324,8 +325,8 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
private void attachMediaController() { |
if (mMediaController != null) { |
mMediaController.setMediaPlayer(this); |
- mMediaController.setAnchorView(sVideoSurfaceView); |
- mMediaController.setEnabled(mHasMediaMetadata); |
+ mMediaController.setAnchorView(mVideoSurfaceView); |
+ mMediaController.setEnabled(true); |
} |
} |
@@ -337,38 +338,12 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
} |
mCurrentBufferPercentage = 0; |
if (mNativeContentVideoView != 0) { |
- int renderHandle = nativeGetRenderHandle(mNativeContentVideoView); |
- if (renderHandle == 0) { |
- nativeSetSurface(mNativeContentVideoView, |
- mSurfaceHolder.getSurface(), |
- nativeGetRouteId(mNativeContentVideoView), |
- nativeGetPlayerId(mNativeContentVideoView)); |
- return; |
- } |
- ISandboxedProcessService service = |
- SandboxedProcessLauncher.getSandboxedService(renderHandle); |
- if (service == null) { |
- Log.e(TAG, "Unable to get SandboxedProcessService from pid."); |
- return; |
- } |
- try { |
- service.setSurface( |
- SET_VIDEO_SURFACE_TEXTURE, |
- mSurfaceHolder.getSurface(), |
- nativeGetRouteId(mNativeContentVideoView), |
- nativeGetPlayerId(mNativeContentVideoView)); |
- } catch (RemoteException e) { |
- Log.e(TAG, "Unable to call setSurfaceTexture: " + e); |
- return; |
- } |
+ nativeSetSurface(mNativeContentVideoView, |
+ mSurfaceHolder.getSurface()); |
} |
requestLayout(); |
invalidate(); |
setMediaController(new MediaController(getChromeActivity())); |
- |
- if (mMediaController != null) { |
- mMediaController.show(); |
- } |
} |
} |
@@ -435,7 +410,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
} |
} else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { |
if (mNativeContentVideoView != 0) { |
- nativeDestroyContentVideoView(mNativeContentVideoView, false); |
+ nativeExitFullscreen(mNativeContentVideoView, false); |
destroyNativeView(); |
} |
return true; |
@@ -530,32 +505,27 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
@CalledByNative |
public static ContentVideoView createContentVideoView(int nativeContentVideoView) { |
+ if (sContentVideoView != null) |
+ return sContentVideoView; |
+ |
if (getChromeActivity() != null) { |
- ContentVideoView videoView = new ContentVideoView(getChromeActivity(), |
+ sContentVideoView = new ContentVideoView(getChromeActivity(), |
nativeContentVideoView); |
- if (sContentVideoView != null) { |
- return videoView; |
- } |
- |
- sContentVideoView = videoView; |
- |
- sContentContainer.setVisibility(View.GONE); |
- sControlContainer.setVisibility(View.GONE); |
sChromeActivity.getWindow().setFlags( |
WindowManager.LayoutParams.FLAG_FULLSCREEN, |
WindowManager.LayoutParams.FLAG_FULLSCREEN); |
- sChromeActivity.getWindow().addContentView(videoView, |
+ sChromeActivity.getWindow().addContentView(sContentVideoView, |
new FrameLayout.LayoutParams( |
ViewGroup.LayoutParams.MATCH_PARENT, |
ViewGroup.LayoutParams.MATCH_PARENT, |
Gravity.CENTER)); |
- videoView.setBackgroundColor(Color.BLACK); |
+ sContentVideoView.setBackgroundColor(Color.BLACK); |
sContentVideoView.showContentVideoView(); |
- videoView.setVisibility(View.VISIBLE); |
- return videoView; |
+ sContentVideoView.setVisibility(View.VISIBLE); |
+ return sContentVideoView; |
} |
return null; |
} |
@@ -564,23 +534,27 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
return sChromeActivity; |
} |
- public static void showFullScreen(ContentVideoView fullscreenView) { |
+ public void removeMediaController() { |
+ if (mMediaController != null) { |
+ mMediaController.setEnabled(false); |
+ mMediaController.hide(); |
+ mMediaController = null; |
+ } |
+ } |
+ public void removeSurfaceView() { |
+ removeView(mVideoSurfaceView); |
+ mVideoSurfaceView = null; |
} |
@CalledByNative |
public static void destroyContentVideoView() { |
sChromeActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); |
if (sContentVideoView != null) { |
- sContentVideoView.removeView(sVideoSurfaceView); |
- sVideoSurfaceView = null; |
+ sContentVideoView.removeMediaController(); |
+ sContentVideoView.removeSurfaceView(); |
sContentVideoView.setVisibility(View.GONE); |
- sRootLayout.removeView(sContentVideoView); |
} |
- |
- sContentContainer.setVisibility(View.VISIBLE); |
- sControlContainer.setVisibility(View.VISIBLE); |
- |
sContentVideoView = null; |
} |
@@ -588,17 +562,13 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
return sContentVideoView; |
} |
- public static void registerChromeActivity(Activity activity, FrameLayout rootLayout, |
- ViewGroup controlContainer, ViewGroup contentContainer) { |
+ public static void registerChromeActivity(Activity activity) { |
sChromeActivity = activity; |
- sRootLayout = rootLayout; |
- sControlContainer = controlContainer; |
- sContentContainer = contentContainer; |
} |
@Override |
public boolean onTouchEvent(MotionEvent ev) { |
- return false; |
+ return true; |
} |
@Override |
@@ -610,20 +580,15 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
return super.onKeyDown(keyCode, event); |
} |
- private native void nativeDestroyContentVideoView(int nativeContentVideoView, |
- boolean relaseMediaPlayer); |
+ private native void nativeExitFullscreen(int nativeContentVideoView, boolean relaseMediaPlayer); |
private native int nativeGetCurrentPosition(int nativeContentVideoView); |
private native int nativeGetDurationInMilliSeconds(int nativeContentVideoView); |
private native void nativeUpdateMediaMetadata(int nativeContentVideoView); |
private native int nativeGetVideoWidth(int nativeContentVideoView); |
private native int nativeGetVideoHeight(int nativeContentVideoView); |
- private native int nativeGetPlayerId(int nativeContentVideoView); |
- private native int nativeGetRouteId(int nativeContentVideoView); |
- private native int nativeGetRenderHandle(int nativeContentVideoView); |
private native boolean nativeIsPlaying(int nativeContentVideoView); |
private native void nativePause(int nativeContentVideoView); |
private native void nativePlay(int nativeContentVideoView); |
private native void nativeSeekTo(int nativeContentVideoView, int msec); |
- private native void nativeSetSurface(int nativeContentVideoView, |
- Surface surface, int routeId, int playerId); |
+ private native void nativeSetSurface(int nativeContentVideoView, Surface surface); |
} |