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 8793301a1391644d9b3c10040da5422808923b58..6c94ad8cdb0d991e4ef057035ae10cbe3fdd2e29 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 |
@@ -69,6 +69,12 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
private static final int STATE_PAUSED = 2; |
private static final int STATE_PLAYBACK_COMPLETED = 3; |
+ // Needs to be kept in sync with content_video_view.h |
+ // Used for full-screen video. |
+ private static final int PERSONALITY_FULL_SCREEN = 0; |
+ // Used for embedded video with external rendering. |
+ private static final int PERSONALITY_EMBEDDED = 1; |
+ |
private SurfaceHolder mSurfaceHolder = null; |
private int mVideoWidth = 0; |
private int mVideoHeight = 0; |
@@ -109,6 +115,8 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
// move this to an instance variable if we allow multiple ContentVideoViews. |
private static ContentVideoViewContextDelegate sDelegate = null; |
+ private final int mPersonality; |
+ |
private class VideoSurfaceView extends SurfaceView { |
public VideoSurfaceView(Context context) { |
@@ -187,19 +195,23 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
}; |
public ContentVideoView(Context context) { |
- this(context, 0); |
+ this(context, 0, PERSONALITY_FULL_SCREEN); |
} |
- public ContentVideoView(Context context, int nativeContentVideoView) { |
+ public ContentVideoView(Context context, int nativeContentVideoView, int personality) { |
super(context); |
initResources(context); |
+ mPersonality = personality; |
+ |
if (nativeContentVideoView == 0) return; |
mNativeContentVideoView = nativeContentVideoView; |
mCurrentBufferPercentage = 0; |
mVideoSurfaceView = new VideoSurfaceView(context); |
- mProgressView = new ProgressView(context); |
+ if (mPersonality == PERSONALITY_FULL_SCREEN) { |
+ mProgressView = new ProgressView(context); |
+ } |
} |
private static void initResources(Context context) { |
@@ -217,15 +229,19 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
ViewGroup.LayoutParams.WRAP_CONTENT, |
Gravity.CENTER); |
this.addView(mVideoSurfaceView, layoutParams); |
- this.addView(mProgressView, layoutParams); |
- mVideoSurfaceView.setZOrderOnTop(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(); |
+ if (mPersonality == PERSONALITY_FULL_SCREEN) { |
+ this.addView(mProgressView, layoutParams); |
+ mVideoSurfaceView.setZOrderOnTop(true); |
+ mVideoSurfaceView.setOnKeyListener(this); |
+ mVideoSurfaceView.setOnTouchListener(this); |
+ mVideoSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); |
+ mVideoSurfaceView.setFocusable(true); |
+ mVideoSurfaceView.setFocusableInTouchMode(true); |
+ mVideoSurfaceView.requestFocus(); |
+ } else { |
+ mVideoSurfaceView.setZOrderMediaOverlay(false); |
+ } |
} |
@CalledByNative |
@@ -300,7 +316,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
boolean canPause, |
boolean canSeekBack, |
boolean canSeekForward) { |
- mProgressView.setVisibility(View.GONE); |
+ if (mProgressView != null) { |
+ mProgressView.setVisibility(View.GONE); |
+ } |
mDuration = duration; |
mCanPause = canPause; |
mCanSeekBack = canSeekBack; |
@@ -327,8 +345,10 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
@Override |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
- mVideoSurfaceView.setFocusable(true); |
- mVideoSurfaceView.setFocusableInTouchMode(true); |
+ if (mPersonality == PERSONALITY_FULL_SCREEN) { |
+ mVideoSurfaceView.setFocusable(true); |
+ mVideoSurfaceView.setFocusableInTouchMode(true); |
+ } |
if (isInPlaybackState() && mMediaController != null) { |
if (mMediaController.isShowing()) { |
// ensure the controller will get repositioned later |
@@ -348,7 +368,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
public void surfaceDestroyed(SurfaceHolder holder) { |
mSurfaceHolder = null; |
if (mNativeContentVideoView != 0) { |
- nativeExitFullscreen(mNativeContentVideoView, true); |
+ if (mPersonality == PERSONALITY_FULL_SCREEN) { |
+ nativeExitFullscreen(mNativeContentVideoView, true); |
+ } |
mNativeContentVideoView = 0; |
post(mExitFullscreenRunnable); |
} |
@@ -375,7 +397,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
public void openVideo() { |
if (mSurfaceHolder != null) { |
mCurrentState = STATE_IDLE; |
- setMediaController(new FullScreenMediaController(sDelegate.getContext(), this)); |
+ if (mPersonality == PERSONALITY_FULL_SCREEN) { |
+ setMediaController(new FullScreenMediaController(sDelegate.getContext(), this)); |
+ } |
if (mNativeContentVideoView != 0) { |
nativeUpdateMediaMetadata(mNativeContentVideoView); |
} |
@@ -450,7 +474,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
} |
} else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { |
if (mNativeContentVideoView != 0) { |
- nativeExitFullscreen(mNativeContentVideoView, false); |
+ if (mPersonality == PERSONALITY_FULL_SCREEN) { |
+ nativeExitFullscreen(mNativeContentVideoView, false); |
+ } |
destroyNativeView(); |
} |
return true; |
@@ -542,18 +568,25 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
} |
@CalledByNative |
- public static ContentVideoView createContentVideoView(int nativeContentVideoView) { |
- if (sContentVideoView != null) |
+ public static ContentVideoView createContentVideoView( |
+ int nativeContentVideoView, int personality) { |
+ if (sContentVideoView != null && sContentVideoView.mPersonality == personality) { |
return sContentVideoView; |
+ } |
if (sDelegate != null && sDelegate.getContext() != null) { |
sContentVideoView = new ContentVideoView(sDelegate.getContext(), |
- nativeContentVideoView); |
+ nativeContentVideoView, personality); |
sDelegate.onShowCustomView(sContentVideoView); |
- sContentVideoView.setBackgroundColor(Color.BLACK); |
sContentVideoView.showContentVideoView(); |
- sContentVideoView.setVisibility(View.VISIBLE); |
+ if (personality == PERSONALITY_FULL_SCREEN) { |
+ sContentVideoView.setBackgroundColor(Color.BLACK); |
+ sContentVideoView.setVisibility(View.VISIBLE); |
+ } else { |
+ sContentVideoView.setBackgroundColor(Color.TRANSPARENT); |
+ sContentVideoView.setVisibility(View.INVISIBLE); |
+ } |
return sContentVideoView; |
} |
return null; |
@@ -569,7 +602,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
public void removeSurfaceView() { |
removeView(mVideoSurfaceView); |
- removeView(mProgressView); |
+ if (mProgressView != null) { |
+ removeView(mProgressView); |
+ } |
mVideoSurfaceView = null; |
mProgressView = null; |
} |