Android应用程序从SD卡播放视频

时间:2017-07-17 08:08:39

标签: android android-videoview

我必须逐个从SD卡播放视频,但SD卡路径有一些问题,如: -

无法打开内容:file:///storage/emulated/0/sachin.mp4

我的代码: -

VideoView videoView =(VideoView)findViewById(R.id.videoView1);

    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    File SDCardRoot = Environment.getExternalStorageDirectory().getAbsoluteFile();

    File file = null;
    file = new File(SDCardRoot, "sachin.mp4");
    Uri uri = Uri.fromFile(file);
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();

1 个答案:

答案 0 :(得分:0)

你是否在清单中给出了这个许可?

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