Hello all…
Today I will show you how to get notified when a video completes playing in android.
PLease check this post for playing a video and the resources.
First create a folder named “raw” inside the “res” folder and copy a video inside it.
Now copy the xml from this link.
For listening to the video completion add a setOnCompletionListener to the VideoView Object.
Here is hoe we do this.
package com.coderzheaven.pack; import android.app.Activity; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.net.Uri; import android.os.Bundle; import android.widget.MediaController; import android.widget.Toast; import android.widget.VideoView; public class VideoViewDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); showVideo(); } private void showVideo() { VideoView vd = (VideoView)findViewById(R.id.videoview); Uri uri = Uri.parse("android.resource://"+ getApplication().getPackageName() +"/"+R.raw.asal); MediaController mc = new MediaController(this); vd.setMediaController(mc); vd.setVideoURI(uri); vd.start(); vd.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Toast.makeText(getApplicationContext(), "Video completed", Toast.LENGTH_LONG).show(); } }); } }