我试图做到这一点,当我点击一个图像框时,视频播放应该停止线程并开始一个新视频。目前,它给了我一个“IllegalStateException”的例外。如何停止线程并开始一个全新的视频?public class VideoActivity extends AppCompatActivity {VideoView videoView;MediaController mController;@Overrideprotected 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();}}
1 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
尝试在代码(Java/Kotlin)而不是 XML 中定义您的 OnClick 侦听器。我假设发生的事情是您android:onClick
为 XML 中的按钮分配了一个,但 android 在您的代码中找不到您的方法。
尝试findViewById
你的观点并分配setOnClickListener
给它。
添加回答
举报
0/150
提交
取消