对话后恢复视频

时间:2014-03-14 23:30:36

标签: java android dialog android-videoview resume

我正在尝试暂停某个位置的视频,显示一个对话框,当它关闭时,视频应该继续。但我不知道在哪里放置videoView.resume()

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();
}

1 个答案:

答案 0 :(得分:0)

你可以在android中使用onDismissListener,参考这个 http://developer.android.com/reference/android/content/DialogInterface.OnDismissListener.html

在此监听器中,您可以在取消对话框后恢复视频