依次播放视频和点击

时间:2018-12-11 18:10:44

标签: java android

Android开发者的新手。 我想先播放一个视频,然后在完成视频后加载第二个视频,然后在单击第二个视频时单击加载第三个视频,而在第三个视频完成后单击第四个视频。

public class MainActivity extends AppCompatActivity {
    VideoView videoView, videoView1, videoView2, videoView3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoView = findViewById(R.id.videoView);
        videoView1 = findViewById(R.id.videoView1);
        videoView2 = findViewById(R.id.videoView2);
        videoView3 = findViewById(R.id.videoView3);
        Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video1);
        videoView.setVideoURI(video);
        videoView.start();

        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.reset();
                Uri video1 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video2);
                videoView1.setVideoURI(video1);
                videoView1.start();
            }
        });

        videoView1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Uri video2 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video3);
                videoView2.setVideoURI(video2);
                videoView2.start();
            }
        });

    }
}

我到目前为止有什么!

0 个答案:

没有答案