WEB开发网
开发学院手机开发Android 开发 android控件之VideoView建立自己的播放器 阅读

android控件之VideoView建立自己的播放器

 2010-11-05 00:57:38 来源:WEB开发网   
核心提示:protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.videoview);this

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();

}

}

上一页  1 2 

Tags:android 控件 VideoView

编辑录入:coldstar [复制链接] [打 印]
赞助商链接