这是我插入 VideoView 的代码,但是当我运行它时,无法播放。
VideoView v =(VideoView) findViewById(R.id.videoView1);
v.setVideoPath("/sdcard/ss.mp4");
v.setMediaController(new MediaController(this));
v.start();
v.requestFocus();
使用Environment.getExternalStorageDirectory()获取外部存储路径而不是静态字符串:
VideoView v =(VideoView) findViewById(R.id.videoView1);
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
v.setVideoPath(baseDir+"/ss.mp4");
v.setMediaController(new MediaController(Your_Current_Activity.this));
v.start();
v.requestFocus();
并确保您在 Androidmanifest.xml 中添加了外部存储权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />