我想使用videoview播放mp4视频(可在android播放),但无法播放视频。
我的视频在sdcard文件夹中,
有人能帮我吗,
这是我的代码:
final VideoView vd = new VideoView(AboutActivity.this);
vd.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.MATCH_PARENT)); linevideo.addView(vd);
MediaController mediaController = new MediaController (this);
mediaController.setAnchorView (vd); vd.setMediaController (mediaController);
Uri video = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/media/vid.mp4");
vd.setVideoURI(video); vd.requestFocus (); vd.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp){
mp.setLooping(true);
vd.start ();
}
});
最佳答案
首先尝试改变
vd.setVideoURI(video);
至
vd.setVideoPath(video);
并检查是否在清单中添加以下权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>