Java 对话后恢复视频
我试图在某个位置暂停视频,显示一个对话框,当它关闭时,视频应该继续。但是我不知道把Java 对话后恢复视频,java,android,dialog,android-videoview,resume,Java,Android,Dialog,Android Videoview,Resume,我试图在某个位置暂停视频,显示一个对话框,当它关闭时,视频应该继续。但是我不知道把videoView.resume()放在哪里 您可以在android中使用onDismissListener,请参阅 在这个监听器中,你可以在关闭对话框后恢复你的视频我像那样尝试了dialog.setOnDismissListener(新建DialogInterface.ondismsListener(){@Override public void onDismiss(DialogInterface dialog
videoView.resume()放在哪里
您可以在android中使用onDismissListener,请参阅
在这个监听器中,你可以在关闭对话框后恢复你的视频我像那样尝试了dialog.setOnDismissListener(新建DialogInterface.ondismsListener(){@Override public void onDismiss(DialogInterface dialog){videoView.resume();})代码>但它不工作如果它不工作,请尝试使您的类实现侦听器,并在活动的onDismiss()方法中恢复videViewresume()不工作,但seekTo()和start()不工作
public void start(boolean tester)
{
File file = new File("android.resource://" + getPackageName() + "/" + R.raw.trailer);
if (!file.setReadable(true)) //zugriff erlauben
{
createError(101);
}
final VideoView videoView = (VideoView) findViewById(R.id.surface_view);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.trailer);
videoView.start(); //video starten
createQuestion(videoView, 6000, "Frage?", "Antwort1", "Antwort2", "Antwort3", "none", R.id.answer2RadioButton);
postData(getUserName(tester), score, false); //highscore senden
//Intent i = new Intent(this, SettingsActivity.class);
//startActivity(i);
}
public void questionDialog(String question, String answer1, String answer2, String answer3, String answer4, final int correctAnswer)
{
killRunnable = true;
// custom dialog
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.question_dialog);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.questionTextView);
text.setText(question);
RadioButton answer1Button = (RadioButton) dialog.findViewById(R.id.answer1RadioButton);
RadioButton answer2Button = (RadioButton) dialog.findViewById(R.id.answer2RadioButton);
RadioButton answer3Button = (RadioButton) dialog.findViewById(R.id.answer3RadioButton);
RadioButton answer4Button = (RadioButton) dialog.findViewById(R.id.answer4RadioButton);
answer1Button.setText(answer1);
answer2Button.setText(answer2);
answer3Button.setText(answer3);
answer4Button.setText(answer4);
if (answer1.equals("none")){answer1Button.setVisibility(View.INVISIBLE);}
if (answer2.equals("none")){answer2Button.setVisibility(View.INVISIBLE);}
if (answer3.equals("none")){answer3Button.setVisibility(View.INVISIBLE);}
if (answer4.equals("none")){answer4Button.setVisibility(View.INVISIBLE);}
Button dialogButton = (Button) dialog.findViewById(R.id.answerButton);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
RadioGroup radioGroup = (RadioGroup) dialog.findViewById(R.id.radioGroup);
if (radioGroup.getCheckedRadioButtonId() == correctAnswer)
{
score += 100;
Toast toast = Toast.makeText(context, "Richtig!", Toast.LENGTH_LONG);
toast.show();
}
else
{
Toast toast = Toast.makeText(context, "Leider falsch.", Toast.LENGTH_LONG);
toast.show();
}
dialog.dismiss();
}
});
dialog.show();
}
public void createQuestion(final VideoView videoView, final int pos, final String question, final String answer1, final String answer2, final String answer3, final String answer4, final int correctAnswer)
{
final Runnable runnable = new Runnable()
{
public void run()
{
if (videoView.getCurrentPosition()>=pos)
{
videoView.pause();
questionDialog(question, answer1, answer2, answer3, answer4, correctAnswer);
//NOT working: videoView.resume();
//TODO resume video
}
if (!killRunnable){videoView.postDelayed(this, 1);}
}
};
runnable.run();
}