-1

I'm developing an application that gets input speech from the user and depending on the sentence, the video will work ... But the video only plays one video each time

public void onActivityResult(int request_code , int result_code , Intent i){
    super.onActivityResult(request_code, result_code, i);
    MediaController mediaController= new MediaController(this);
    mediaController.setAnchorView(resultvid);
    resultvid.setMediaController(mediaController);
    CharSequence h1 = "hello";
    CharSequence h2 = "i";
    CharSequence h3 = "want";
    CharSequence h4 = "water";
    CharSequence h5 = "thank you";

    switch (request_code){
        case 100: if(result_code == RESULT_OK && i != null ){
            ArrayList<String> result = i.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            resultTEXT.setText(result.get(0));


                if (String.valueOf(result).contains(h1)) {


                }  else if (String.valueOf(result).contains(h2)) {
                    resultvid.setVideoPath("file:///storage/sdcard0/srtosl/me.mp4");


                }  else if (String.valueOf(result).contains(h3)) {
                    resultvid.setVideoPath("file:///storage/sdcard0/srtosl/want.mp4");

                }  else if (String.valueOf(result).contains(h4)) {
                    resultvid.setVideoPath("file:///storage/sdcard0/srtosl/water.mp4");

                }  else if (String.valueOf(result).contains(h5)) {
                    resultvid.setVideoPath("file:///storage/sdcard0/srtosl/thankyou.mp4");

                }

                resultvid.start();



            break;

        }
    }

If the user inputs "I want water", I need all videos to play one by one. Thank you

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
sal
  • 1
  • 1

1 Answers1

1

The VideoView / MediaPlayer has a setOnCompletionListener(MediaPlayer.OnCompletionListener l) method. Once the video finishes playing, you can move onto the next.

Also worth reading: What is the difference between MediaPlayer and VideoView in Android

Community
  • 1
  • 1
An SO User
  • 24,612
  • 35
  • 133
  • 221