No, you don't need to change to a MediaPlayer for it to work. I think
your code doesn't hang, you just haven't told it what to do after
playing the video and that is why it is "stuck" there.
Setting up the onCompletionListener() is the same as setting up
listeners for button clicks. I added some lines to your code:
public class Videos extends Activity {
@Override
protected void onCreate( Bundle savedInstanceState ){
// recover the name of the video to play
Bundle bundle = getIntent().getExtras();
String video_to_play = bundle.getString("Value");
// set the screen up
super.onCreate(savedInstanceState);
setContentView( R.layout.videos );
// set up to play the video
VideoView video = (VideoView)
findViewById( R.id.vidview);
video.setVideoPath( video_to_play );
video.setOnCompletionListener(setOnCompletionListener(new
OnCompletionListener() { // <------- What to do when playback finishes
public void onCompletion(MediaPlayer mp) {
finish();
}
});
video.setMediaController(new MediaController(this)); //
<-----------
If you want to show the controller
video.start();
}
}
Also, I think it would be better if you can show a progress bar or
something while the video loads. Just so the user won't think that
nothing is happening.
Best of luck!
- Zarah.
On Dec 16, 1:18 am, vtb <[email protected]> wrote:
> Hi Zarah
> I really appreciate you getting back to me. I did put a finsh(); in
> the code but the
> code is in error and won't compile
>
> Here is the code before adding, this works but obviously hangs at the
> end of the video
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.VideoView;
>
> public class Videos extends Activity {
>
> @Override
> protected void onCreate( Bundle savedInstanceState ){
> // recover the name of the video to play
> Bundle bundle = getIntent().getExtras();
> String video_to_play = bundle.getString("Value");
> // set the screen up
> super.onCreate(savedInstanceState);
> setContentView( R.layout.videos );
> // set up to play the video
> VideoView video = (VideoView) findViewById( R.id.vidview);
> video.setVideoPath( video_to_play );
> video.start();
> }
>
> }
>
> When I try an add a video setonComplettionListener( video ) I get
> The method set or onCompletionListener() is undefined for the type
> VideoView
>
> Any further advice would be very much appreciated
>
> Perhaps the couple of luines from your code showing how to set the
> listener up and the listener.
>
> One thought is do i have to change to a MediaPlayer reather than
> VideoView to get this to work?
>
> Thank you and best regards
>
> Viv
>
> On Dec 14, 8:09 am, Zarah <[email protected]> wrote:
>
>
>
>
>
>
>
> > I am not a guru, but I have tried using VideoView.
>
> > I am using onCompletionListener() without any problems. Did you call
> > finish() in your onCompletionListener()?
>
> > - Zarah.
>
> > On Dec 14, 12:11 am, vtb <[email protected]> wrote:
>
> > > Hi Guru's
> > > New to Android.
> > > I am developing an app that plays videos based on a touch map that is
> > > read from the local disk, this map defines areas of the screen that
> > > relate to a particular video to play. This is all working very nicely
> > > now. However, when the video completes I have to hit the button on the
> > > front of the table to return to the calling screen for any subsequent
> > > selection(s).
>
> > > I have tried implementing an onCompleteListener() for VideoView
> > > without any success. Do you have any ideas or can you point me to any
> > > reference code that would possibly help.
>
> > > Thanking you in advance for any help you can give.
>
> > > Seasons greetings
>
> > > Viv
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en