连续播放内部存储器中的视频

时间:2018-11-18 05:10:01

标签: java android-studio android-videoview

我将一些MP4保存到了模拟的Android上的“下载”文件夹中,并试图连续循环播放每个MP4。但这不起作用。我在做什么错了?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_kiosk);

    linkedList = new LinkedList<String>();
    File file = new File(Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DOWNLOADS + File.separator);
    Log.d("kiosk_onCreate", "file: " + String.valueOf(file));
    File[] list = file.listFiles();
    Log.d("kiosk_onCreate", "list: " + String.valueOf(list));
    for (File f : list) {
        String name = f.getName();
        if (name.endsWith(".mp4")) {
            path = file.getAbsolutePath() + name;
            linkedList.add(path);
        }

    }

    videoView.setOnCompletionListener(new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            String video = (String) linkedList.get(0);
            Log.d("kiosk_onCompletion", "video: " + video);
            linkedList.remove(0);
            linkedList.add(video);
            startVideo();
        }
    });
}

public void startVideo()
{
    VideoView videoView1 = findViewById(R.id.videoView);
    String path = (String) linkedList.get(0);
    Log.d("kiosk_startVideo", "path: " + path);
    videoView1.setVideoURI(Uri.parse(path));
    videoView1.start();

}

AndroidManifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

0 个答案:

没有答案