Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listener (or handler) for video finish

I have implement the following code in order to test playing a video from a remote web server through it´s URL.

videoView = (VideoView)this.findViewById(R.id.videoView);         MediaController mc = new MediaController(this);         videoView.setMediaController(mc);         videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));         videoView.requestFocus(); 

The code is working just fine, even in the Android emulator. I just would like to know if there's any listener (or handler) to detect the finish of the video that is being reproduced?

Update:

I have the following code now:

   @Override         protected void onCreate(Bundle savedInstanceState) {                  super.onCreate(savedInstanceState);         this.setContentView(R.layout.player);                  videoView = (VideoView)this.findViewById(R.id.videoView);         playVideo();                  // video finish listener         videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {                          @Override             public void onCompletion(MediaPlayer mp) {                 // not playVideo                             // playVideo();                                                          mp.start();             }         });     }      public void playVideo() {             MediaController mc = new MediaController(this);             videoView.setMediaController(mc);             videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));             videoView.requestFocus();          } 

When the activity is just called, the video works fine but when the video finishes, I would like that it played again, which it's not occurring.

like image 897
Rui Gonçalves Avatar asked Dec 04 '09 15:12

Rui Gonçalves


1 Answers

Seems you are looking for

setOnCompletionListener(MediaPlayer.OnCompletionListener l) 

More in depth explanation can be found here

EDIT

This shows a solution where playback is called after completion using VideoView, MediaController and setOnCompletionListener().

like image 185
Anthony Forloney Avatar answered Sep 18 '22 03:09

Anthony Forloney