import android.annotation.TargetApi;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;


public class FullscreenActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_fullscreen);



        VideoView vv1 = (VideoView) findViewById(R.id.fullscreen_content);
            vv1.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part1);
            vv1.start();


        vv1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv2 = (VideoView) findViewById(R.id.fullscreen_content);
                vv2.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part2);
                vv2.start();
            }

        });

        vv2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv3 = (VideoView) findViewById(R.id.fullscreen_content);
                vv3.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part3);
                vv3.start();
            }
        });


        vv3.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv4 = (VideoView) findViewById(R.id.fullscreen_content);
                vv4.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part4);
                vv4.start();
            }

        });


        vv4.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv42 = (VideoView) findViewById(R.id.fullscreen_content);
                vv42.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part4_2);
                vv42.start();
            }
        });


        vv42.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv5 = (VideoView) findViewById(R.id.fullscreen_content);
                vv5.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part5);
                vv5.start();
            }
        });


    }

}

嘿大家

所以这是我目前的代码。基本上,我想要连续显示6个视频。因此,我明白了这一点,但现在他告诉我vv2(及以后的版本)无法解决。

我是Javascript初学者,所以我不知道这意味着什么,只是我认为他没有该变量集导致其在onCompletion函数中定义。

那么如何从onCompletion中获取vv2?

还是还有其他可能的方法?也许$ i++有循环?

最佳答案

vv2和其他版本无法解析,因为您在onCompletion方法中本地声明了它们。所以,是的,您应该使用计数器或其他物品,然后再以这种方式播放视频。

public class FullscreenActivity extends Activity {

    private int[] data = new int[]{R.raw.intro_video_part1, R.raw.intro_video_part2,
     R.raw.intro_video_part3, R.raw.intro_video_part4, R.raw.intro_video_part5, R.raw.intro_video_part6};

    int counter = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_fullscreen);

    VideoView vv1 = (VideoView) findViewById(R.id.fullscreen_content);
                vv1.setVideoPath("android.resource://" + getPackageName() + "/" + data[counter]);
                vv1.start();

            vv1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    counter++;
                    vv1.setVideoPath("android.resource://" + getPackageName() + "/" + data[counter]);
                    vv1.start();
                }

            });
}

10-08 15:20