I need to create Activity, which will play video from URL. Right now, I use VideoView and MediaController, and when this activity creates, after buffering video it should plays. It works, but plays only once, after that media controller works but don't plays video.
Here is piece of code:
private ProgressDialog progressDialog;
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Some title");
progressDialog.setMessage("Buffering...");
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.show();
videoView = (VideoView) findViewById(R.id.video_view);
Intent intent = getIntent();
String url = intent.getStringExtra("extra_url");
Uri uri = Uri.parse(url);
videoView.setVideoURI(uri, HeadersMap); // Here I put my headers - I need to do that.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}
So, what's problem? Why video can't repeat again? I set cursor to start on controller, but nothing happens. How I can handle it? Or what I should to do?
Thank you for answers!
Try this,
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
Also you can do it with setOnCompletionListener
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
videoView.start();
}
});
OR
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
mVideoView.start();
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.reset();
videoView.setVideoURI(uri, HeadersMap);
}
});