我试图做到这一点,当我点击一个图像框时,视频播放应该停止线程并开始一个新视频。目前,它给了我一个“IllegalStateException”的例外。
如何停止线程并开始一个全新的视频?
public class VideoActivity extends AppCompatActivity {
VideoView videoView;
MediaController mController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.introductie);
}
protected void onClick(View v)
{
videoView.stopPlayback();
switch(v.getId())
{
case R.id.imageView2:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.introductie);
break;
case R.id.imageView3:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.wel_iets_aan_de_hand3);
break;
case R.id.imageView4:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.hoe_moet_je_plassen4);
break;
case R.id.imageView5:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.wanneer_moet_je_plassen5);
break;
case R.id.imageView6:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.hoe_haak_moet_je_plassen6);
break;
case R.id.imageView7:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.piponormaalvrachtwagens7);
break;
case R.id.imageView8:
playVideo("android.resource://"+ getPackageName() + "/" + R.raw.pipoobstipatievrachtwagens8);
break;
}
}
protected void playVideo(String videoName)
{
videoView = findViewById(R.id.videoViewId);
mController = new MediaController(this);
videoView.setVideoPath(videoName);
mController.setAnchorView(videoView);
videoView.setMediaController(mController);
videoView.start();
}
}
慕标5832272
相关分类