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.
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.
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); } });
In Kotlin simply use
videoView.setOnPreparedListener { it.isLooping = true }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With