<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
2.定义 VideoView
<VideoView android:id="@+id/video" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" />
3. Activity:
public VideoView videoView;//声明Video 对象
videoView=(VideoView)findViewById(R.id.video);
public void playVedio(){ File file =new File("/sdcard/Movies/视频9 再制图像.flv");//获取SD上的文件---flv格式可以播放
// File file =new File("/sdcard/Movies/01.杨光福_Android_JNI_什么jni.avi");//获取SD上的文件---avi ---有声音无图像
// File file =new File("/sdcard/Movies/Wildlife.wmv");//获取SD上的文件---提示无文件
//实例化媒体控制器 MediaController mediaController=new MediaController(this); if(file.exists()){ videoView.setVideoPath(file.getAbsolutePath());//指定要播放的视频 videoView.setMediaController(mediaController);//设置 VideoView与 MediaCtroller关联 videoView.requestFocus();//让video获得焦点 try{ videoView.start(); }catch (Exception e){ e.printStackTrace(); Toast.makeText(MyActivity.this,"视频播放出错",Toast.LENGTH_SHORT).show(); } videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Toast.makeText(MyActivity.this,"视频播放完毕",Toast.LENGTH_SHORT).show(); } }); }else{ Toast.makeText(MyActivity.this,"视频文件不存在",Toast.LENGTH_SHORT).show(); } }安卓默认支持的视频格式: 3gp mp4