给Android VideoView一个文件目录,就可以直接播放智能设备中的视频文件,现在以播放事先用手机拍好并重命名的视频文件test.mp4为例。 
(1) 需要在布局文件中写一个ViedoView: 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.videoview.MainActivity" > 
 
    <VideoView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/videoView" /> 
 
</RelativeLayout> 
 
(2)不要忘记在AndroidManifest.xml文件中添加读写外部存储的权限: 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
 
(3)在java代码中给VideoView设置文件目录,然后start播放: 
public class MainActivity extends Activity { 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
 
        VideoView videoView = (VideoView) findViewById(R.id.videoView); 
 
        // 获得的path等于:/storage/emulated/0/DCIM 
        File path = Environment 
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); 
 
        // 拼接完整路径 
        File f = new File(path, "/Camera/test.mp4"); 
 
        // 此时的f.getAbsolutePath()=/storage/emulated/0/DCIM//\Camera/test.mp4 
        videoView.setVideoPath(f.getAbsolutePath()); 
 
        // 开始播放视频 
        videoView.start(); 
 
        // VideiView获焦点 
        // videoView.requestFocus(); 
    } 
} 
 
以上!另外对APP进行全方位的检测,我都会用这个:www.ineice.com。 
 |   
        
 
    
    
    
     
 
 |