views:

812

answers:

2

Hi there!

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?

Thanks in advance for the help, Best regards!

+1  A: 

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().

Anthony Forloney
But I'm not using MediaPlayer but yes MediaController. It's not kind of different?
Rui Gonçalves
+1  A: 

Hi again!

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, wich it's not occurring.

Can anyone give me some help?

Thanks in advance, Best regards!

Rui Gonçalves
Instead of invoking `playVideo()` try calling `mp.start()`
Anthony Forloney
Yes, I had already replaced it in my code.Thank you for all the help!Best regards!
Rui Gonçalves
No problem, glad I can help. Best Regards to you as well :)
Anthony Forloney