Clean up VideoView, SurfaceView constructors
Also cleans up VideoView fields. No functional changes. Bug: 30600463 Change-Id: I42241e376006c328695d46d63f7fdeda409f1a67
This commit is contained in:
@@ -193,26 +193,20 @@ public class SurfaceView extends View {
|
|||||||
private boolean mGlobalListenersAdded;
|
private boolean mGlobalListenersAdded;
|
||||||
|
|
||||||
public SurfaceView(Context context) {
|
public SurfaceView(Context context) {
|
||||||
super(context);
|
this(context, null);
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SurfaceView(Context context, AttributeSet attrs) {
|
public SurfaceView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
this(context, attrs, 0);
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
this(context, attrs, defStyleAttr, 0);
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public SurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
setWillNotDraw(true);
|
setWillNotDraw(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,46 +70,49 @@ import java.util.Vector;
|
|||||||
*/
|
*/
|
||||||
public class VideoView extends SurfaceView
|
public class VideoView extends SurfaceView
|
||||||
implements MediaPlayerControl, SubtitleController.Anchor {
|
implements MediaPlayerControl, SubtitleController.Anchor {
|
||||||
private String TAG = "VideoView";
|
private static final String TAG = "VideoView";
|
||||||
// settable by the client
|
|
||||||
private Uri mUri;
|
|
||||||
private Map<String, String> mHeaders;
|
|
||||||
|
|
||||||
// all possible internal states
|
// all possible internal states
|
||||||
private static final int STATE_ERROR = -1;
|
private static final int STATE_ERROR = -1;
|
||||||
private static final int STATE_IDLE = 0;
|
private static final int STATE_IDLE = 0;
|
||||||
private static final int STATE_PREPARING = 1;
|
private static final int STATE_PREPARING = 1;
|
||||||
private static final int STATE_PREPARED = 2;
|
private static final int STATE_PREPARED = 2;
|
||||||
private static final int STATE_PLAYING = 3;
|
private static final int STATE_PLAYING = 3;
|
||||||
private static final int STATE_PAUSED = 4;
|
private static final int STATE_PAUSED = 4;
|
||||||
private static final int STATE_PLAYBACK_COMPLETED = 5;
|
private static final int STATE_PLAYBACK_COMPLETED = 5;
|
||||||
|
|
||||||
|
private final Vector<Pair<InputStream, MediaFormat>> mPendingSubtitleTracks = new Vector<>();
|
||||||
|
|
||||||
|
// settable by the client
|
||||||
|
private Uri mUri;
|
||||||
|
private Map<String, String> mHeaders;
|
||||||
|
|
||||||
// mCurrentState is a VideoView object's current state.
|
// mCurrentState is a VideoView object's current state.
|
||||||
// mTargetState is the state that a method caller intends to reach.
|
// mTargetState is the state that a method caller intends to reach.
|
||||||
// For instance, regardless the VideoView object's current state,
|
// For instance, regardless the VideoView object's current state,
|
||||||
// calling pause() intends to bring the object to a target state
|
// calling pause() intends to bring the object to a target state
|
||||||
// of STATE_PAUSED.
|
// of STATE_PAUSED.
|
||||||
private int mCurrentState = STATE_IDLE;
|
private int mCurrentState = STATE_IDLE;
|
||||||
private int mTargetState = STATE_IDLE;
|
private int mTargetState = STATE_IDLE;
|
||||||
|
|
||||||
// All the stuff we need for playing and showing a video
|
// All the stuff we need for playing and showing a video
|
||||||
private SurfaceHolder mSurfaceHolder = null;
|
private SurfaceHolder mSurfaceHolder = null;
|
||||||
private MediaPlayer mMediaPlayer = null;
|
private MediaPlayer mMediaPlayer = null;
|
||||||
private int mAudioSession;
|
private int mAudioSession;
|
||||||
private int mVideoWidth;
|
private int mVideoWidth;
|
||||||
private int mVideoHeight;
|
private int mVideoHeight;
|
||||||
private int mSurfaceWidth;
|
private int mSurfaceWidth;
|
||||||
private int mSurfaceHeight;
|
private int mSurfaceHeight;
|
||||||
private MediaController mMediaController;
|
private MediaController mMediaController;
|
||||||
private OnCompletionListener mOnCompletionListener;
|
private OnCompletionListener mOnCompletionListener;
|
||||||
private MediaPlayer.OnPreparedListener mOnPreparedListener;
|
private MediaPlayer.OnPreparedListener mOnPreparedListener;
|
||||||
private int mCurrentBufferPercentage;
|
private int mCurrentBufferPercentage;
|
||||||
private OnErrorListener mOnErrorListener;
|
private OnErrorListener mOnErrorListener;
|
||||||
private OnInfoListener mOnInfoListener;
|
private OnInfoListener mOnInfoListener;
|
||||||
private int mSeekWhenPrepared; // recording the seek position while preparing
|
private int mSeekWhenPrepared; // recording the seek position while preparing
|
||||||
private boolean mCanPause;
|
private boolean mCanPause;
|
||||||
private boolean mCanSeekBack;
|
private boolean mCanSeekBack;
|
||||||
private boolean mCanSeekForward;
|
private boolean mCanSeekForward;
|
||||||
|
|
||||||
/** Subtitle rendering widget overlaid on top of the video. */
|
/** Subtitle rendering widget overlaid on top of the video. */
|
||||||
private RenderingWidget mSubtitleWidget;
|
private RenderingWidget mSubtitleWidget;
|
||||||
@@ -118,13 +121,11 @@ public class VideoView extends SurfaceView
|
|||||||
private RenderingWidget.OnChangedListener mSubtitlesChangedListener;
|
private RenderingWidget.OnChangedListener mSubtitlesChangedListener;
|
||||||
|
|
||||||
public VideoView(Context context) {
|
public VideoView(Context context) {
|
||||||
super(context);
|
this(context, null);
|
||||||
initVideoView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoView(Context context, AttributeSet attrs) {
|
public VideoView(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
initVideoView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public VideoView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
@@ -133,7 +134,19 @@ public class VideoView extends SurfaceView
|
|||||||
|
|
||||||
public VideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public VideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
initVideoView();
|
|
||||||
|
mVideoWidth = 0;
|
||||||
|
mVideoHeight = 0;
|
||||||
|
|
||||||
|
getHolder().addCallback(mSHCallback);
|
||||||
|
getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||||
|
|
||||||
|
setFocusable(true);
|
||||||
|
setFocusableInTouchMode(true);
|
||||||
|
requestFocus();
|
||||||
|
|
||||||
|
mCurrentState = STATE_IDLE;
|
||||||
|
mTargetState = STATE_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -209,19 +222,6 @@ public class VideoView extends SurfaceView
|
|||||||
return getDefaultSize(desiredSize, measureSpec);
|
return getDefaultSize(desiredSize, measureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initVideoView() {
|
|
||||||
mVideoWidth = 0;
|
|
||||||
mVideoHeight = 0;
|
|
||||||
getHolder().addCallback(mSHCallback);
|
|
||||||
getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
||||||
setFocusable(true);
|
|
||||||
setFocusableInTouchMode(true);
|
|
||||||
requestFocus();
|
|
||||||
mPendingSubtitleTracks = new Vector<Pair<InputStream, MediaFormat>>();
|
|
||||||
mCurrentState = STATE_IDLE;
|
|
||||||
mTargetState = STATE_IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets video path.
|
* Sets video path.
|
||||||
*
|
*
|
||||||
@@ -294,8 +294,6 @@ public class VideoView extends SurfaceView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector<Pair<InputStream, MediaFormat>> mPendingSubtitleTracks;
|
|
||||||
|
|
||||||
public void stopPlayback() {
|
public void stopPlayback() {
|
||||||
if (mMediaPlayer != null) {
|
if (mMediaPlayer != null) {
|
||||||
mMediaPlayer.stop();
|
mMediaPlayer.stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user