kg96
kg96

Reputation: 73

How to loop a video in a videoview that uses URI

So, i wanted to make an app with a video in the background and whenever the app starts, the video will play, but one problem is it only plays one time and never loops. Here is my code

 @Override
    protected void onResume() {
    super.onResume();
    VideoView video = (VideoView) findViewById(R.id.videoview1);
    Uri videoPath = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.great);
    video.setVideoURI(videoPath);
    video.start();
    }

Upvotes: 3

Views: 2582

Answers (1)

Alex Baban
Alex Baban

Reputation: 11732

Try with OnPreparedListener.

@Override
    protected void onResume() {
    super.onResume();
    VideoView video = (VideoView) findViewById(R.id.videoview1);

    video.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.setLooping(true);
        }
    });

    Uri videoPath = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.great);
    video.setVideoURI(videoPath);
    video.start();
    } 

Upvotes: 5

Related Questions