public class ObservableVideoView extends VideoView { private IVideoViewActionListener mVideoViewListener; private boolean mIsOnPauseMode = false; public interface IVideoViewActionListener { void onPause(); void onResume(); void onTimeBarSeekChanged(int currentTime); } public void setVideoViewListener(IVideoViewActionListener listener) { mVideoViewListener = listener; } @Override public void pause() { super.pause(); if (mVideoViewListener != null) { mVideoViewListener.onPause(); } mIsOnPauseMode = true; } @Override public void start() { super.start(); if (mIsOnPauseMode) { if (mVideoViewListener != null) { mVideoViewListener.onResume(); } mIsOnPauseMode = false; } } @Override public void seekTo(int msec) { super.seekTo(msec); if (mVideoViewListener != null) { mVideoViewListener.onTimeBarSeekChanged(msec); } } public ObservableVideoView(Context context, AttributeSet attrs) { super(context, attrs); } public ObservableVideoView(Context context) { super(context); } public ObservableVideoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); }
}
You can listen to such events:
public class VideoPlayerActivity extends Activity { public static final String VIDEO_URL = "VideoUrl"; private String path = ""; private ObservableVideoView mVideoView; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.video_player_activity_layout); mVideoView = (ObservableVideoView) findViewById(R.id.videoView1); mVideoView.setMediaController(new MediaController(this)); mVideoView.setVideoViewListener(mVideoViewListener); path = getIntent().getStringExtra(VIDEO_URL); if (path == "") { Toast.makeText(this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG) .show(); } else { mVideoView.setVideoPath(path); mVideoView.requestFocus(); mVideoView.start(); } } private IVideoViewActionListener mVideoViewListener = new IVideoViewActionListener() { @Override public void onTimeBarSeekChanged(int currentTime) {
}
source share