在这个应用程序中,我们希望在观看时没有任何延迟地显示连续视频。每个视频的 uri 存储在一个数组中,我们通过循环显示这些视频,但视频和其他视频之间的演示存在延迟。如何解决这个问题?
public class ShowActivity extends AppCompatActivity {
VideoView video;
ProgressDialog pd;
int currentPlayingIndex = 0;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
video=findViewById(R.id.videoView);
pd=new ProgressDialog(ShowActivity.this);
Bundle b=getIntent().getExtras();
String[] arrayresulturi=b.getStringArray("uriresult");
video=findViewById(R.id.videoView);
Uri uri = Uri.parse(arrayresulturi[0]);
video.setVideoURI(uri);
video.start();
video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
currentPlayingIndex++;
if (arrayresulturi[currentPlayingIndex] != null) {
mp.setLooping(true);
Uri uri = Uri.parse(arrayresulturi[currentPlayingIndex]);
video.setVideoURI(uri);
video.start();
}// end if()
else {
video.stopPlayback();
Intent backIntent = new Intent(ShowActivity.this,MainActivity.class);
startActivity(backIntent);
}//end else
}//end onCompletion
});//end setOnCompletionListener()
}//end onCreate()
}//结束类