Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seamless video Loop with VideoView

I have the following code to take a video as a raw resource, start the video and loop it but I need the video to loop seamlessly as of now when it comes to an end of the clip and starts the clip again the transition between causes a flicker for a split second, which I really can't have for my app.

public class Example extends Activity {     VideoView vv;     /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          vv = (VideoView)findViewById(R.id.VideoView01);          //Video Loop         vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {             public void onCompletion(MediaPlayer mp) {                 vv.start(); //need to make transition seamless.             }         });          Uri uri = Uri.parse("android.resource://com.example/"                 + R.raw.video);          vv.setVideoURI(uri);         vv.requestFocus();             vv.start();     } } 

The clip is only 22 seconds long but was created to be seamless so it is possible to work without the delay.

like image 686
SamRowley Avatar asked Jan 20 '11 10:01

SamRowley


People also ask

Can you make Vimeo loop?

If you'd like your embedded video to autoplay or loop, go to the video's page on vimeo.com and click the "Share" button in the upper right corner of the video player. In the window that opens, click the "Show options" link, and check the corresponding boxes next to "Loop this video," "Autoplay this video," or both.


2 Answers

Try this it will work 100%


VideoView videoView;<---write this in outside of method or else declare it as final variable.

videoView.setOnPreparedListener(new OnPreparedListener() {     @Override     public void onPrepared(MediaPlayer mp) {         mp.setLooping(true);     } }); 
like image 159
PravinDodia Avatar answered Sep 19 '22 11:09

PravinDodia


In Kotlin simply use

videoView.setOnPreparedListener { it.isLooping = true } 
like image 43
Chirag Kalra Avatar answered Sep 21 '22 11:09

Chirag Kalra