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 64685e20f0514fd58af0dccde74b365dbb231d6c..894cc4b3497f70e08a928798346076fb0d4bd2b9 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; |
private int mVideoHeight; |
@@ -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) { |
@@ -183,19 +191,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) { |
@@ -213,15 +225,17 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
ViewGroup.LayoutParams.WRAP_CONTENT, |
Gravity.CENTER); |
this.addView(mVideoSurfaceView, layoutParams); |
- this.addView(mProgressView, layoutParams); |
- mVideoSurfaceView.setZOrderMediaOverlay(true); |
- mVideoSurfaceView.setOnKeyListener(this); |
- mVideoSurfaceView.setOnTouchListener(this); |
+ mVideoSurfaceView.setZOrderMediaOverlay(mPersonality == PERSONALITY_FULL_SCREEN); |
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.setOnKeyListener(this); |
+ mVideoSurfaceView.setOnTouchListener(this); |
+ mVideoSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); |
+ mVideoSurfaceView.setFocusable(true); |
+ mVideoSurfaceView.setFocusableInTouchMode(true); |
+ mVideoSurfaceView.requestFocus(); |
+ } |
} |
@CalledByNative |
@@ -296,7 +310,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; |
@@ -323,8 +339,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 |
@@ -344,7 +362,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); |
} |
@@ -371,7 +391,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); |
} |
@@ -446,7 +468,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; |
@@ -538,18 +562,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; |
@@ -565,7 +596,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl, |
public void removeSurfaceView() { |
removeView(mVideoSurfaceView); |
- removeView(mProgressView); |
+ if (mProgressView != null) { |
+ removeView(mProgressView); |
+ } |
mVideoSurfaceView = null; |
mProgressView = null; |
} |