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 89b4e8a82ed198c78e3592d333b961fa75ec79a6..0adda264fa0316ad3f1f27bdce23ec28e34a9c23 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 |
@@ -8,11 +8,9 @@ import android.app.Activity; |
import android.app.AlertDialog; |
import android.content.Context; |
import android.content.DialogInterface; |
-import android.graphics.Color; |
import android.util.Log; |
import android.view.Gravity; |
import android.view.KeyEvent; |
-import android.view.MotionEvent; |
import android.view.Surface; |
import android.view.SurfaceHolder; |
import android.view.SurfaceView; |
@@ -20,7 +18,6 @@ import android.view.View; |
import android.view.ViewGroup; |
import android.widget.FrameLayout; |
import android.widget.LinearLayout; |
-import android.widget.MediaController; |
import android.widget.ProgressBar; |
import android.widget.TextView; |
@@ -29,8 +26,7 @@ import org.chromium.base.JNINamespace; |
import org.chromium.base.ThreadUtils; |
@JNINamespace("content") |
-public class ContentVideoView extends FrameLayout implements MediaController.MediaPlayerControl, |
- SurfaceHolder.Callback, View.OnTouchListener, View.OnKeyListener { |
+public class ContentVideoView extends FrameLayout implements SurfaceHolder.Callback { |
private static final String TAG = "ContentVideoView"; |
@@ -63,12 +59,7 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
private SurfaceHolder mSurfaceHolder; |
private int mVideoWidth; |
private int mVideoHeight; |
- private int mCurrentBufferPercentage; |
private int mDuration; |
- private MediaController mMediaController; |
- private boolean mCanPause; |
- private boolean mCanSeekBack; |
- private boolean mCanSeekForward; |
// Native pointer to C++ ContentVideoView object. |
private long mNativeContentVideoView; |
@@ -131,32 +122,6 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
} |
- private static class FullScreenMediaController extends MediaController { |
- |
- View mVideoView; |
- |
- public FullScreenMediaController(Context context, View video) { |
- super(context); |
- mVideoView = video; |
- } |
- |
- @Override |
- public void show() { |
- super.show(); |
- if (mVideoView != null) { |
- mVideoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); |
- } |
- } |
- |
- @Override |
- public void hide() { |
- if (mVideoView != null) { |
- mVideoView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); |
- } |
- super.hide(); |
- } |
- } |
- |
private final Runnable mExitFullscreenRunnable = new Runnable() { |
@Override |
public void run() { |
@@ -164,15 +129,13 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
}; |
- private ContentVideoView(Context context, long nativeContentVideoView, |
+ protected ContentVideoView(Context context, long nativeContentVideoView, |
ContentVideoViewClient client) { |
super(context); |
mNativeContentVideoView = nativeContentVideoView; |
mClient = client; |
initResources(context); |
- mCurrentBufferPercentage = 0; |
mVideoSurfaceView = new VideoSurfaceView(context); |
- setBackgroundColor(Color.BLACK); |
showContentVideoView(); |
setVisibility(View.VISIBLE); |
mClient.onShowCustomView(this); |
@@ -192,31 +155,25 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
org.chromium.content.R.string.media_player_loading_video); |
} |
- private void showContentVideoView() { |
- FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( |
+ protected void showContentVideoView() { |
Ted C
2013/12/26 23:06:15
All non-private methods should have java doc
|
+ mVideoSurfaceView.getHolder().addCallback(this); |
+ this.addView(mVideoSurfaceView, new FrameLayout.LayoutParams( |
ViewGroup.LayoutParams.MATCH_PARENT, |
ViewGroup.LayoutParams.MATCH_PARENT, |
- Gravity.CENTER); |
- this.addView(mVideoSurfaceView, layoutParams); |
- View progressView = mClient.getVideoLoadingProgressView(); |
- if (progressView != null) { |
- mProgressView = progressView; |
- } else { |
+ Gravity.CENTER)); |
+ |
+ mProgressView = mClient.getVideoLoadingProgressView(); |
+ if (mProgressView == null) { |
mProgressView = new ProgressView(getContext(), mVideoLoadingText); |
} |
this.addView(mProgressView, new FrameLayout.LayoutParams( |
ViewGroup.LayoutParams.WRAP_CONTENT, |
ViewGroup.LayoutParams.WRAP_CONTENT, |
Gravity.CENTER)); |
- mVideoSurfaceView.setZOrderOnTop(true); |
- mVideoSurfaceView.setOnKeyListener(this); |
- mVideoSurfaceView.setOnTouchListener(this); |
- mVideoSurfaceView.getHolder().addCallback(this); |
- mVideoSurfaceView.setFocusable(true); |
- mVideoSurfaceView.setFocusableInTouchMode(true); |
- mVideoSurfaceView.requestFocus(); |
} |
+ protected SurfaceView getSurfaceView() { return mVideoSurfaceView; } |
Ted C
2013/12/26 23:06:15
I would put the return on the subsequent line. I
|
+ |
@CalledByNative |
public void onMediaPlayerError(int errorType) { |
Log.d(TAG, "OnMediaPlayerError: " + errorType); |
@@ -230,9 +187,6 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
mCurrentState = STATE_ERROR; |
- if (mMediaController != null) { |
- mMediaController.hide(); |
- } |
/* Pop up an error dialog so the user knows that |
* something bad has happened. Only try and pop up the dialog |
@@ -281,8 +235,7 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
@CalledByNative |
- private void onBufferingUpdate(int percent) { |
- mCurrentBufferPercentage = percent; |
+ protected void onBufferingUpdate(int percent) { |
} |
@CalledByNative |
@@ -291,38 +244,21 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
@CalledByNative |
- private void onUpdateMediaMetadata( |
+ protected void onUpdateMediaMetadata( |
int videoWidth, |
int videoHeight, |
int duration, |
boolean canPause, |
boolean canSeekBack, |
boolean canSeekForward) { |
- mProgressView.setVisibility(View.GONE); |
mDuration = duration; |
- mCanPause = canPause; |
- mCanSeekBack = canSeekBack; |
- mCanSeekForward = canSeekForward; |
+ mProgressView.setVisibility(View.GONE); |
mCurrentState = isPlaying() ? STATE_PLAYING : STATE_PAUSED; |
- if (mMediaController != null) { |
- mMediaController.setEnabled(true); |
- // If paused , should show the controller for ever. |
- if (isPlaying()) |
- mMediaController.show(); |
- else |
- mMediaController.show(0); |
- } |
- |
onVideoSizeChanged(videoWidth, videoHeight); |
} |
@Override |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
- mVideoSurfaceView.setFocusable(true); |
- mVideoSurfaceView.setFocusableInTouchMode(true); |
- if (isInPlaybackState() && mMediaController != null) { |
- mMediaController.show(); |
- } |
} |
@Override |
@@ -340,28 +276,10 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
post(mExitFullscreenRunnable); |
} |
- private void setMediaController(MediaController controller) { |
- if (mMediaController != null) { |
- mMediaController.hide(); |
- } |
- mMediaController = controller; |
- attachMediaController(); |
- } |
- |
- private void attachMediaController() { |
- if (mMediaController != null) { |
- mMediaController.setMediaPlayer(this); |
- mMediaController.setAnchorView(mVideoSurfaceView); |
- mMediaController.setEnabled(false); |
- } |
- } |
- |
@CalledByNative |
- private void openVideo() { |
+ protected void openVideo() { |
if (mSurfaceHolder != null) { |
mCurrentState = STATE_IDLE; |
- mCurrentBufferPercentage = 0; |
- setMediaController(new FullScreenMediaController(getContext(), this)); |
if (mNativeContentVideoView != 0) { |
nativeUpdateMediaMetadata(mNativeContentVideoView); |
nativeSetSurface(mNativeContentVideoView, |
@@ -370,90 +288,16 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
} |
- private void onCompletion() { |
+ protected void onCompletion() { |
mCurrentState = STATE_PLAYBACK_COMPLETED; |
- if (mMediaController != null) { |
- mMediaController.hide(); |
- } |
- } |
- |
- @Override |
- public boolean onTouch(View v, MotionEvent event) { |
- if (isInPlaybackState() && mMediaController != null && |
- event.getAction() == MotionEvent.ACTION_DOWN) { |
- toggleMediaControlsVisiblity(); |
- } |
- return true; |
- } |
- |
- @Override |
- public boolean onTrackballEvent(MotionEvent ev) { |
- if (isInPlaybackState() && mMediaController != null) { |
- toggleMediaControlsVisiblity(); |
- } |
- return false; |
- } |
- |
- @Override |
- public boolean onKey(View v, int keyCode, KeyEvent event) { |
- boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && |
- keyCode != KeyEvent.KEYCODE_VOLUME_UP && |
- keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && |
- keyCode != KeyEvent.KEYCODE_VOLUME_MUTE && |
- keyCode != KeyEvent.KEYCODE_CALL && |
- keyCode != KeyEvent.KEYCODE_MENU && |
- keyCode != KeyEvent.KEYCODE_SEARCH && |
- keyCode != KeyEvent.KEYCODE_ENDCALL; |
- if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) { |
- if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || |
- keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { |
- if (isPlaying()) { |
- pause(); |
- mMediaController.show(); |
- } else { |
- start(); |
- mMediaController.hide(); |
- } |
- return true; |
- } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { |
- if (!isPlaying()) { |
- start(); |
- mMediaController.hide(); |
- } |
- return true; |
- } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP |
- || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { |
- if (isPlaying()) { |
- pause(); |
- mMediaController.show(); |
- } |
- return true; |
- } else { |
- toggleMediaControlsVisiblity(); |
- } |
- } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { |
- exitFullscreen(false); |
- return true; |
- } else if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_SEARCH) { |
- return true; |
- } |
- return super.onKeyDown(keyCode, event); |
} |
- private void toggleMediaControlsVisiblity() { |
- if (mMediaController.isShowing()) { |
- mMediaController.hide(); |
- } else { |
- mMediaController.show(); |
- } |
- } |
- private boolean isInPlaybackState() { |
+ protected boolean isInPlaybackState() { |
return (mCurrentState != STATE_ERROR && mCurrentState != STATE_IDLE); |
} |
- @Override |
- public void start() { |
+ protected void start() { |
if (isInPlaybackState()) { |
if (mNativeContentVideoView != 0) { |
nativePlay(mNativeContentVideoView); |
@@ -462,8 +306,7 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
} |
- @Override |
- public void pause() { |
+ protected void pause() { |
if (isInPlaybackState()) { |
if (isPlaying()) { |
if (mNativeContentVideoView != 0) { |
@@ -475,8 +318,7 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
// cache duration as mDuration for faster access |
- @Override |
- public int getDuration() { |
+ protected int getDuration() { |
if (isInPlaybackState()) { |
if (mDuration > 0) { |
return mDuration; |
@@ -492,51 +334,23 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
return mDuration; |
} |
- @Override |
- public int getCurrentPosition() { |
+ protected int getCurrentPosition() { |
if (isInPlaybackState() && mNativeContentVideoView != 0) { |
return nativeGetCurrentPosition(mNativeContentVideoView); |
} |
return 0; |
} |
- @Override |
- public void seekTo(int msec) { |
+ protected void seekTo(int msec) { |
if (mNativeContentVideoView != 0) { |
nativeSeekTo(mNativeContentVideoView, msec); |
} |
} |
- @Override |
- public boolean isPlaying() { |
+ protected boolean isPlaying() { |
return mNativeContentVideoView != 0 && nativeIsPlaying(mNativeContentVideoView); |
} |
- @Override |
- public int getBufferPercentage() { |
- return mCurrentBufferPercentage; |
- } |
- |
- @Override |
- public boolean canPause() { |
- return mCanPause; |
- } |
- |
- @Override |
- public boolean canSeekBackward() { |
- return mCanSeekBack; |
- } |
- |
- @Override |
- public boolean canSeekForward() { |
- return mCanSeekForward; |
- } |
- |
- @Override |
- public int getAudioSessionId() { |
- return 0; |
- } |
- |
@CalledByNative |
private static ContentVideoView createContentVideoView( |
Context context, long nativeContentVideoView, ContentVideoViewClient client) { |
@@ -549,12 +363,16 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
return new ContentVideoView(context, nativeContentVideoView, client); |
} |
- private void removeMediaController() { |
- if (mMediaController != null) { |
- mMediaController.setEnabled(false); |
- mMediaController.hide(); |
- mMediaController = null; |
+ @CalledByNative |
+ private static ContentVideoView createContentVideoViewLegacy( |
Ted C
2013/12/26 23:06:15
why is this in this file instead of ContentVideoVi
trchen
2013/12/26 23:22:46
Then we'll have to generate another JNI header for
Ted C
2013/12/27 00:15:35
Do we plan on removing ContentVideoViewLegacy at s
|
+ Context context, long nativeContentVideoView, ContentVideoViewClient client) { |
+ ThreadUtils.assertOnUiThread(); |
+ // The context needs be Activity to create the ContentVideoView correctly. |
+ if (!(context instanceof Activity)) { |
+ Log.w(TAG, "Wrong type of context, can't create fullscreen video"); |
Ted C
2013/12/26 23:06:15
should this be an assert?
trchen
2013/12/26 23:22:46
I don't know. It is copy & paste from createConten
|
+ return null; |
} |
+ return new ContentVideoViewLegacy(context, nativeContentVideoView, client); |
} |
public void removeSurfaceView() { |
@@ -577,9 +395,8 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
* To exit fullscreen, use exitFullscreen in Java. |
*/ |
@CalledByNative |
- private void destroyContentVideoView(boolean nativeViewDestroyed) { |
+ protected void destroyContentVideoView(boolean nativeViewDestroyed) { |
if (mVideoSurfaceView != null) { |
- removeMediaController(); |
removeSurfaceView(); |
setVisibility(View.GONE); |
@@ -596,17 +413,12 @@ public class ContentVideoView extends FrameLayout implements MediaController.Med |
} |
@Override |
- public boolean onTouchEvent(MotionEvent ev) { |
- return true; |
- } |
- |
- @Override |
- public boolean onKeyDown(int keyCode, KeyEvent event) { |
- if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { |
+ public boolean onKeyUp(int keyCode, KeyEvent event) { |
+ if (keyCode == KeyEvent.KEYCODE_BACK) { |
exitFullscreen(false); |
return true; |
} |
- return super.onKeyDown(keyCode, event); |
+ return super.onKeyUp(keyCode, event); |
} |
private static native ContentVideoView nativeGetSingletonJavaContentVideoView(); |