1

I want to play the video one by one from my sdcard using Texture view in android. I am using tetureview bcoz , I want to rotate the video at 90 degree.. so I can play the rotated video on device by implementing SurfaceTextureListener interface.

This is the code:

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
    root = Environment.getExternalStorageDirectory();
    ArrayList extList = new ArrayList<String>();
    extList.add("mp4");
    extList.add("3gp");
    extList.add("ts");
    extList.add("webm");
    extList.add("mkv");
    Intent intent = getIntent();
    Bundle b = intent.getExtras();
    vFiles = b.getStringArrayList("vFiles");
    System.out.println("VFiles: " + vFiles);
    iterator = vFiles.iterator();
    videoPath = root + "/Video/";

    if (iterator.hasNext()) {
        System.out.println("Inside iterator: .......................................");
        String video = videoPath + iterator.next();

        mMediaPlayer = new MediaPlayer();
        //mMediaPlayer.setDataSource(afd.getFileDescriptor(),
        //  afd.getStartOffset(), afd.getLength());
        mMediaPlayer.setDataSource(video);
        System.out.println("After Datasource: " + video);
        mMediaPlayer.setSurface(sur);
        //  mMediaPlayer.setLooping(true);
        mMediaPlayer.prepareAsync();
        // mMediaPlayer.setOnBufferingUpdateListener((OnBufferingUpdateListener) this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnCompletionListener(this);

        // Play video when the media source is ready for playback.
        mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                //  mediaPlayer.setLooping(true);

                mediaPlayer.start();
            }
        });
    }
}

But By this code, Only one video is playing , after another video is not playing.. and I want when one video is finished then second video in the list should be play and so on..

I searched a lot about this on net... But no luck...

Can any one help me regarding this ?

Antonio Pérez
  • 6,702
  • 4
  • 36
  • 61
Archana Sarang
  • 101
  • 1
  • 9

1 Answers1

3

onSurfaceTextureAvailable method doesn't get triggered when the MediaPlayer object has completed playback, it gets triggered when the Surface texture is ready to be used.

You need to implement MediaPlayer.OnCompletionListener, the onCompletion method gets triggered once the playback is completed.

Start the playback of the next video in the list once the playback of the first video is completed.

bluefalcon
  • 4,225
  • 1
  • 32
  • 41
  • Hi, @bluefalcon, But, – Archana Sarang Sep 08 '15 at 11:40
  • @ArchanaSarang but ?? - you missed some text I guess :) – bluefalcon Sep 08 '15 at 11:53
  • yes, but, my videos are not playing sequentially .. i have implement onCompletion method.. with calling finish method. It's just close the activity . I want to play sequence of the videos.. – Archana Sarang Sep 08 '15 at 12:56
  • Yes, `finish` method will close the activity. You don't want to do that. `onCompletion` method indicates the first video playback is completed, so now you can restart the `mediaplayer` object with the path to the new video and start the playback. – bluefalcon Sep 09 '15 at 03:39