| 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 e14bf04f8f95cf466bb51b9c4a1fea93a6af61fa..885c91a7def26dfc083b26734920a798eb136055 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
|
| @@ -32,6 +32,7 @@ import java.lang.ref.WeakReference;
|
|
|
| import org.chromium.base.CalledByNative;
|
| import org.chromium.base.JNINamespace;
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.content.common.IChildProcessService;
|
| import org.chromium.content.R;
|
|
|
| @@ -66,28 +67,31 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| private static final int STATE_PAUSED = 2;
|
| private static final int STATE_PLAYBACK_COMPLETED = 3;
|
|
|
| - private SurfaceHolder mSurfaceHolder = null;
|
| - private int mVideoWidth = 0;
|
| - private int mVideoHeight = 0;
|
| + // There are can be at most 1 fullscreen video
|
| + private static ContentVideoView sContentVideoView;
|
| +
|
| + private SurfaceHolder mSurfaceHolder;
|
| + private int mVideoWidth;
|
| + private int mVideoHeight;
|
| private int mCurrentBufferPercentage;
|
| private int mDuration;
|
| - private MediaController mMediaController = null;
|
| + private MediaController mMediaController;
|
| private boolean mCanPause;
|
| private boolean mCanSeekBack;
|
| private boolean mCanSeekForward;
|
|
|
| // Native pointer to C++ ContentVideoView object.
|
| - private int mNativeContentVideoView = 0;
|
| + private int mNativeContentVideoView;
|
|
|
| // webkit should have prepared the media
|
| private int mCurrentState = STATE_IDLE;
|
|
|
| // Strings for displaying media player errors
|
| - static String mPlaybackErrorText;
|
| - static String mUnknownErrorText;
|
| - static String mErrorButton;
|
| - static String mErrorTitle;
|
| - static String mVideoLoadingText;
|
| + private String mPlaybackErrorText;
|
| + private String mUnknownErrorText;
|
| + private String mErrorButton;
|
| + private String mErrorTitle;
|
| + private String mVideoLoadingText;
|
|
|
| // This view will contain the video.
|
| private VideoSurfaceView mVideoSurfaceView;
|
| @@ -95,16 +99,9 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| // Progress view when the video is loading.
|
| private View mProgressView;
|
|
|
| - private Surface mSurface = null;
|
| -
|
| - // There are can be at most 1 fullscreen video
|
| - // TODO(qinmin): will change this once we move the creation of this class
|
| - // to the host application
|
| - private static ContentVideoView sContentVideoView = null;
|
| + private Surface mSurface;
|
|
|
| - // The delegate will follow sContentVideoView. We would need to
|
| - // move this to an instance variable if we allow multiple ContentVideoViews.
|
| - private static ContentVideoViewContextDelegate sDelegate = null;
|
| + private ContentVideoViewClient mClient;
|
|
|
| private class VideoSurfaceView extends SurfaceView {
|
|
|
| @@ -136,7 +133,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| private ProgressBar mProgressBar;
|
| private TextView mTextView;
|
|
|
| - public ProgressView(Context context) {
|
| + public ProgressView(Context context, String videoLoadingText) {
|
| super(context);
|
| setOrientation(LinearLayout.VERTICAL);
|
| setLayoutParams(new LinearLayout.LayoutParams(
|
| @@ -144,7 +141,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| LinearLayout.LayoutParams.WRAP_CONTENT));
|
| mProgressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
|
| mTextView = new TextView(context);
|
| - mTextView.setText(mVideoLoadingText);
|
| + mTextView.setText(videoLoadingText);
|
| addView(mProgressBar);
|
| addView(mTextView);
|
| }
|
| @@ -183,22 +180,21 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| }
|
| };
|
|
|
| - public ContentVideoView(Context context) {
|
| - this(context, 0);
|
| - }
|
| -
|
| - private ContentVideoView(Context context, int nativeContentVideoView) {
|
| + private ContentVideoView(Context context, int nativeContentVideoView,
|
| + ContentVideoViewClient client) {
|
| super(context);
|
| - initResources(context);
|
| -
|
| - if (nativeContentVideoView == 0) return;
|
| mNativeContentVideoView = nativeContentVideoView;
|
| -
|
| + mClient = client;
|
| + initResources(context);
|
| mCurrentBufferPercentage = 0;
|
| mVideoSurfaceView = new VideoSurfaceView(context);
|
| + mClient.onShowCustomView(this);
|
| + setBackgroundColor(Color.BLACK);
|
| + showContentVideoView();
|
| + setVisibility(View.VISIBLE);
|
| }
|
|
|
| - private static void initResources(Context context) {
|
| + private void initResources(Context context) {
|
| if (mPlaybackErrorText != null) return;
|
| mPlaybackErrorText = context.getString(
|
| org.chromium.content.R.string.media_player_error_text_invalid_progressive_playback);
|
| @@ -218,11 +214,11 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| ViewGroup.LayoutParams.WRAP_CONTENT,
|
| Gravity.CENTER);
|
| this.addView(mVideoSurfaceView, layoutParams);
|
| - View progressView = sDelegate.getVideoLoadingProgressView();
|
| + View progressView = mClient.getVideoLoadingProgressView();
|
| if (progressView != null) {
|
| mProgressView = progressView;
|
| } else {
|
| - mProgressView = new ProgressView(getContext());
|
| + mProgressView = new ProgressView(getContext(), mVideoLoadingText);
|
| }
|
| this.addView(mProgressView, layoutParams);
|
| mVideoSurfaceView.setZOrderOnTop(true);
|
| @@ -374,11 +370,10 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| }
|
| }
|
|
|
| - @CalledByNative
|
| public void openVideo() {
|
| if (mSurfaceHolder != null) {
|
| mCurrentState = STATE_IDLE;
|
| - setMediaController(new FullScreenMediaController(sDelegate.getContext(), this));
|
| + setMediaController(new FullScreenMediaController(getContext(), this));
|
| if (mNativeContentVideoView != 0) {
|
| nativeUpdateMediaMetadata(mNativeContentVideoView);
|
| }
|
| @@ -475,6 +470,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| return (mCurrentState != STATE_ERROR && mCurrentState != STATE_IDLE);
|
| }
|
|
|
| + @Override
|
| public void start() {
|
| if (isInPlaybackState()) {
|
| if (mNativeContentVideoView != 0) {
|
| @@ -484,6 +480,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| }
|
| }
|
|
|
| + @Override
|
| public void pause() {
|
| if (isInPlaybackState()) {
|
| if (isPlaying()) {
|
| @@ -496,6 +493,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| }
|
|
|
| // cache duration as mDuration for faster access
|
| + @Override
|
| public int getDuration() {
|
| if (isInPlaybackState()) {
|
| if (mDuration > 0) {
|
| @@ -512,6 +510,7 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| return mDuration;
|
| }
|
|
|
| + @Override
|
| public int getCurrentPosition() {
|
| if (isInPlaybackState() && mNativeContentVideoView != 0) {
|
| return nativeGetCurrentPosition(mNativeContentVideoView);
|
| @@ -519,47 +518,51 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| return 0;
|
| }
|
|
|
| + @Override
|
| public void seekTo(int msec) {
|
| if (mNativeContentVideoView != 0) {
|
| nativeSeekTo(mNativeContentVideoView, msec);
|
| }
|
| }
|
|
|
| + @Override
|
| public 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;
|
| }
|
|
|
| @CalledByNative
|
| - public static ContentVideoView createContentVideoView(int nativeContentVideoView) {
|
| - if (sContentVideoView != null)
|
| - return sContentVideoView;
|
| -
|
| - if (sDelegate != null && sDelegate.getContext() != null) {
|
| - sContentVideoView = new ContentVideoView(sDelegate.getContext(),
|
| - nativeContentVideoView);
|
| -
|
| - sDelegate.onShowCustomView(sContentVideoView);
|
| - sContentVideoView.setBackgroundColor(Color.BLACK);
|
| - sContentVideoView.showContentVideoView();
|
| - sContentVideoView.setVisibility(View.VISIBLE);
|
| - return sContentVideoView;
|
| + private static ContentVideoView createContentVideoView(Context context,
|
| + int nativeContentVideoView, ContentVideoViewClient client) {
|
| + ThreadUtils.assertOnUiThread();
|
| + if (sContentVideoView != null) {
|
| + assert(nativeContentVideoView == sContentVideoView.mNativeContentVideoView &&
|
| + client == sContentVideoView.mClient);
|
| + sContentVideoView.openVideo();
|
| + } else {
|
| + if (client == null) return null;
|
| + sContentVideoView = new ContentVideoView(context, nativeContentVideoView, client);
|
| }
|
| - return null;
|
| + return sContentVideoView;
|
| }
|
|
|
| public void removeMediaController() {
|
| @@ -578,25 +581,17 @@ public class ContentVideoView extends FrameLayout implements MediaPlayerControl,
|
| }
|
|
|
| @CalledByNative
|
| - public static void destroyContentVideoView() {
|
| - sDelegate.onDestroyContentVideoView();
|
| - if (sContentVideoView != null) {
|
| - sContentVideoView.removeMediaController();
|
| - sContentVideoView.removeSurfaceView();
|
| - sContentVideoView.setVisibility(View.GONE);
|
| - }
|
| - sContentVideoView = null;
|
| + public void destroyContentVideoView() {
|
| + mClient.onDestroyContentVideoView();
|
| + removeMediaController();
|
| + removeSurfaceView();
|
| + setVisibility(View.GONE);
|
| }
|
|
|
| public static ContentVideoView getContentVideoView() {
|
| return sContentVideoView;
|
| }
|
|
|
| - public static void registerContentVideoViewContextDelegate(
|
| - ContentVideoViewContextDelegate delegate) {
|
| - sDelegate = delegate;
|
| - }
|
| -
|
| @Override
|
| public boolean onTouchEvent(MotionEvent ev) {
|
| return true;
|
|
|