VideoView一般结合MediaController类使用,它会提供一个友好的图形界面,通过该界面可以控制视频的播放
package com.test.videoview; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.graphics.PixelFormat; import android.view.Menu; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends Activity { private VideoView videoView; private MediaController controller; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.main); videoView = (VideoView) findViewById(R.id.videoView); controller = new MediaController(this); videoView.setKeepScreenOn(true); // 转换raw资源文件下的文件为Uri对象 videoView.setVideoURI(Uri.parse("android.resource://com.test.videoview/"+R.raw.video)); videoView.setMediaController(controller); controller.setMediaPlayer(videoView); videoView.requestFocus(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }