我有 3 部电影附加到 aVideoView
和 3 个按钮back
:forward
和home
。
我想在循环中使用back
-按钮滚动浏览它们。
当我点击键到达最后一部电影时,我希望第一部电影重新开始,并且与键相同,当我到达第一部电影时,最后一个开始。 forward
forward
back
我知道这可能是一个简单的问题,但我是 android 新手,我就是想不通。
非常感谢!!!
这是我的主要活动代码:
public class Blue extends Activity implements OnClickListener{
ImageButton back;
ImageButton home;
ImageButton forward;
VideoView vid;
int count_back=2;
int count_fw=1;
String urlpath1;
String urlpath2;
String urlpath3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blue);
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
back = (ImageButton) findViewById(R.id.back);
back.setOnClickListener(this);
home = (ImageButton) findViewById(R.id.home);
home.setOnClickListener(this);
forward = (ImageButton) findViewById(R.id.forward);
forward.setOnClickListener(this);
vid = (VideoView) findViewById(R.id.videoView1);
urlpath1 = "android.resource://"+ getPackageName()+"/"+R.raw.blue_01;
urlpath2 = "android.resource://"+ getPackageName()+"/"+R.raw.blue_02;
urlpath3 = "android.resource://"+ getPackageName()+"/"+R.raw.blue_03;
vid.setVideoPath(urlpath1);
vid.requestFocus();
vid.start();
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.home:
vid.stopPlayback();
Intent i = new Intent(Blue.this,MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
break;
case R.id.forward:
if(count_fw==0){vid.setVideoPath(urlpath1);count_fw++;count_back=2;vid.requestFocus();
vid.start();}
else if(count_fw==1){vid.setVideoPath(urlpath2);count_fw++;count_back=0;vid.requestFocus();
vid.start();}
else if(count_fw==2){vid.setVideoPath(urlpath3);count_fw=0;count_back=1;vid.requestFocus();
vid.start();}
break;
case R.id.back:
if(count_back==0){vid.setVideoPath(urlpath1);count_back=2;count_fw=1;vid.requestFocus();
vid.start();}
else if(count_back==1){vid.setVideoPath(urlpath2);count_back--;count_fw=2;
vid.requestFocus();vid.start();}
else if(count_back==2){vid.setVideoPath(urlpath3);count_back--;count_fw=0;
vid.requestFocus();vid.start();}
break;
}
}
@Override
public void onDestroy(){
vid.stopPlayback();
super.onDestroy();
}
}