1

I have an xml file with videoview:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   android:background="@drawable/back"
    android:orientation="vertical" 
    android:screenOrientation="landscape">


<VideoView
            android:id="@+id/videoview_concept"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

And My java part is:

public class playvideos extends Activity implements OnCompletionListener{
    public Integer index_val=0;
    @Override
    public void onCompletion(MediaPlayer mediaPlayer) {
        index_val++;
        VideoView videoview= (VideoView)findViewById(R.id.videoview_concept);
        checkdbconn();
        videoview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_val]));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.start();


    }
    public void playvideo(View view){
            setContentView(R.layout.playvid);
            VideoView videoview= (VideoView)findViewById(R.id.videoview_concept);
            Log.i("Video URL",videourl_array[index_val]);
            checkdbconn();
            videoview.setVideoURI(Uri.parse(videourl_array[index_val]));
            videoview.setMediaController(new MediaController(this));
            videoview.requestFocus();
            checkdbconn();
            videoview.start();

        }

The above code is a button click event. It works really well. If one first video finished, it should automatically play the second video. Thus I want to play all the videos in that array continuously. How to achieve this? Please help me out:)

GOBINATH.M
  • 663
  • 2
  • 12
  • 24

2 Answers2

2

At last I found out how to play all videos which urls are stored in an array. When I play the video sometimes it plays two videos one by one and sometimes only one video was playing. This is how I over come this problem. Thanks to @Kirit.

public void playvideos_all(){
        videoview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_val]));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.start();
        videoview.setClickable(true);
        index_val++;
        if(index_val>=no_of_videos){
            Toast.makeText(getApplicationContext(), "Videos are finished index: "+index_val+"no of videos:"+no_of_videos, Toast.LENGTH_LONG).show();
        }
        else{
        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion (MediaPlayer mp) {
                mp.stop();
                videoview.stopPlayback();
                videoview.suspend();
                playvideos_all();
            }
        });
        }
    }
GOBINATH.M
  • 663
  • 2
  • 12
  • 24
1
public class MainActivity extends Activity implements OnCompletionListener{

    @Override
    public void onCompletion(MediaPlayer mediaPlayer) {
         // play next video

    }
}
Kirit Vaghela
  • 12,572
  • 4
  • 76
  • 80
  • I tried this: @Override public void onCompletion(MediaPlayer mediaPlayer) { index_val++; VideoView videoview= (VideoView)findViewById(R.id.videoview_concept); checkdbconn(); videoview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_val])); videoview.setMediaController(new MediaController(this)); videoview.requestFocus(); videoview.start(); } – GOBINATH.M Aug 03 '13 at 08:26
  • first check whether this method is call after video completion or not. – Kirit Vaghela Aug 03 '13 at 13:08
  • I thought onCompletion() function is called automatically. How to verify this is being called or not? – GOBINATH.M Aug 06 '13 at 05:57
  • Simple add log or System.out.println() statement – Kirit Vaghela Aug 06 '13 at 06:20
  • almost you helped me. This code sometimes working and some times not working. What do I do? – GOBINATH.M Aug 06 '13 at 12:11
  • please check this project may it help you https://github.com/NandoVelazquez/Android-Video-Player-Example – Kirit Vaghela Aug 07 '13 at 05:46