Android: onSeekCompleteListener with VideoView

I am using VideoView to play video files. I use the seekTo function to play the video from where it was stopped. However, I wanted to perform some operations when the search operation was completed. For this I need to use onSeekCompleteListener; however, onSeekCompleteListener is not supported using VideoView; It can be used with MediaPlayer. My question is that "is there a way I can use onSeekCompleteListener" with VideoView?

thanks a lot

+4
source share
3 answers
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) { //TODO what you want } @Override public void onResume() { //TODO what you want } @Override public void onPause() { //TODO what you want } }; 

}

+9
source

No need to create custom VideoView .

You can access MediaPlayer from the onPrepared VideoView method, and then set OnSeekCompleteListener , for example:

 mVideoView.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setOnSeekCompleteListener(new OnSeekCompleteListener() { @Override public void onSeekComplete(MediaPlayer mp) { //TODO: Your code here } }); } }); 
+17
source

Farhan, you're right, onSeekCompleteListener is not supported by VideoView.

But you can copy and configure the VideoView class locally to add this support yourself.

I will show how to do this in my answer to 7990784 .

+1
source

All Articles