如何在Android中播放超过视频

时间:2015-10-05 18:38:25

标签: android video android-videoview

我正在开发一个从用户那里获取输入语音的应用程序,根据句子,视频会正常工作......但视频每次只播放一个视频

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;

        }
    }

如果用户输入&#34;我想要水&#34;,我需要逐个播放所有视频。 谢谢

1 个答案:

答案 0 :(得分:1)

VideoView / MediaPlayersetOnCompletionListener(MediaPlayer.OnCompletionListener l)方法。视频播放完毕后,您可以转到下一个视频。

另外值得一读:What is the difference between MediaPlayer and VideoView in Android