MediaController controller=new MediaController(this); videoView=(VideoView)this.findViewById(R.id.videoView1); controller.setAnchorView(videoView); videoView.setMediaController(controller); System.out.println(Environment.getExternalStorageDirectory().getPath()); System.out.println(Environment.getExternalStorageDirectory().getAbsolutePath()); //获取SD卡 路径 final File file=new File(Environment.getExternalStorageDirectory().getPath()+"/Samsung/Video/Hello.mp4"); if (!file.exists()) { System.out.println("文件不存在"); }else { System.out.println("文件存在"); } this.findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub System.out.println(file.getAbsolutePath()); videoView.setVideoPath(Environment.getExternalStorageDirectory().getPath()+"/Samsung/Video/Hello.mp4"); // videoView.setVideoPath(file.getAbsolutePath()); videoView.start(); } });
注意:
1.SD卡路径问题,最好使用Environment.getExternalStorageDirectory().getAbsolutePath() 因为有的手机的sd卡路径并不是“/mnt/sdcard/”
2.
videoView.setVideoPath(Environment.getExternalStorageDirectory().getPath()+"/Samsung/Video/Hello.mp4");
videoView.setVideoPath(file.getAbsolutePath());
有时路径问题,太变态