android控件之VideoView建立自己的播放器
2010-11-05 00:57:38 来源:WEB开发网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");
//Create media controller
mMediaController = new MediaController(this);
//设置MediaController
mVideoView.setMediaController(mMediaController);
}
//监听MediaPlayer上报的错误信息
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
return false;
}
//Video播完的时候得到通知
@Override
public void onCompletion(MediaPlayer mp) {
this.finish();
}
//开始
public void onStart() {
// Play Video
mVideoView.setVideoURI(mUri);
mVideoView.start();
super.onStart();
}
//暂停
public void onPause() {
// Stop video when the activity is pause.
mPositionWhenPaused = mVideoView.getCurrentPosition();
mVideoView.stopPlayback();
Log.d(TAG, "OnStop: mPositionWhenPaused = " + mPositionWhenPaused);
Log.d(TAG, "OnStop: getDuration = " + mVideoView.getDuration());
super.onPause();
}
public void onResume() {
// Resume video player
if(mPositionWhenPaused >= 0) {
mVideoView.seekTo(mPositionWhenPaused);
mPositionWhenPaused = -1;
}
super.onResume();
}
}
更多精彩
赞助商链接