Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play video one after another simultaneously smoothly [without visible switching from one to another]

I am new to android and want to play videos one after another simultaneously so that it looks like continuous video.

I have found this link on stackoverflow very helpful. how-to-play-videos-one-after-another-simultaneously When I am using this then though I am able to play videos one after another, But switching from one segment to other results in pause the video for a second before playing next one. So It don't looks like continuous videos due to this.

Please help me to resolve my problem. Here is my Code.

public class VideoActivity extends Activity{

     VideoView videoView, videoView1;
     MediaController mc;
     int count = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);

        videoView = (VideoView) findViewById(R.id.VVSimpleVideo);
        setup();
        videoView.setOnCompletionListener(completionListener);

    }

    public void setup() {

        String _path = "/mnt/sdcard/Video/"+count+".mp4";
        videoView.setVideoPath(_path);
        videoView.start();
        count++;
    }


    private OnCompletionListener completionListener=new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            mp.stop();
            setup();
        }
    };

}

Now I have tried to play by taking two instances of VideoView class. Tried to play the first video by first player and second video by second player, Third video from first player and fourth video from second player and so on.

But still I am not able to play the video smoothly and the same problem exist.

Here is my code with double player.

public class VideoActivity extends Activity{

     VideoView videoView, videoView1;
     MediaController mc;
     int count = 0;
     String _path;
     String _path1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);

        videoView = (VideoView) findViewById(R.id.VVSimpleVideo);
        _path = "/mnt/sdcard/Video/"+count+".mp4";
        videoView.setVideoPath(_path);
         videoView.start();
        //setup();
        videoView.setOnCompletionListener(completionListener);

        videoView1 = (VideoView) findViewById(R.id.VVSimpleVideo);

        videoView1.setOnCompletionListener(completionListener1);
        count++;
        _path1 = "/mnt/sdcard/Video/"+count+".mp4";
        videoView1.setVideoPath(_path1);
    }

    public void setup() {


        videoView.start();
        count++;
        _path1 = "/mnt/sdcard/Video/"+count+".mp4";
        videoView1.setVideoPath(_path1);
    }

    public void setup1() {


        videoView1.start();

        count++;
        _path = "/mnt/sdcard/Video/"+count+".mp4";
        videoView.setVideoPath(_path);
    }

    private OnCompletionListener completionListener=new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            mp.stop();
            setup1();       

        }
    };

    private OnCompletionListener completionListener1=new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            mp.stop();

            setup();        

        }
    };

}
like image 313
piku Avatar asked Nov 02 '12 12:11

piku


1 Answers

You're not really using two VideoViews at all, you're assigning both VideoView and VideoView1 to R.id.VVSimpleVideo, so they are the same object. That means each time you hit onCompletion, it's setting itself up all over again, instead of setting up one and playing the other.

Try creating two separate VideoView objects in your layout. Have one set to VISIBLE and one set to GONE/INVISIBLE, and swap when you want to change.

I can't guarantee it will make it "seamless", though, since that's an almost impossible task. Even most desktop media players aren't truly seamless. It just depends on what tolerance you have for seams.

like image 170
Geobits Avatar answered Nov 02 '22 23:11

Geobits