我将一些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"/>