Mexican 2011-03-04
简介
用来播放视频文件。该VideoView类可以加载各种来源的图像(如资源或内容提供商),需要计算它从视频测量,以便它可以在任何布局管理器使用,并提供诸如缩放和着色的各种显示选项。在其他的平台上面可能VideoPlayer开发是一个比较有挑战性的工作,但是在Android上面VideoPlayer的开发,基本上可以做到傻瓜式啦。本文简单对VideoPlayer的开发进行简单的介绍。
实例
1.布局文件
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout
xmlns:android="android:layout_height="wrap_content">
< VideoView android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;
public static final String TAG = "VideoPlayer";
private int mPositionWhenPaused = -1;
private MediaController mMediaController;
* @see android.app.Activity#onCreate(android.os.Bundle)
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView = (VideoView)findViewById(R.id.videoview);
mUri = Uri.parse(Environment.getExternalStorageDirectory() + "/ziranyouli.3gp");
mMediaController = new MediaController(this);
mVideoView.setMediaController(mMediaController);
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
public void onCompletion(MediaPlayer mp) {
// Stop video when the activity is pause.
mPositionWhenPaused = mVideoView.getCurrentPosition();
Log.d(TAG, "OnStop: mPositionWhenPaused = " + mPositionWhenPaused);
Log.d(TAG, "OnStop: getDuration = " + mVideoView.getDuration());
if(mPositionWhenPaused >= 0) {
mVideoView.seekTo(mPositionWhenPaused);