Android UI(7)Building Apps with Multimedia - Capturing Photo

Android UI(7)Building Apps with Multimedia - Capturing Photo

2. Recording Videos Simply
Request Camera Permission
<uses-featureandroid:name="android.hardware.camera"/>

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Record a Video with a Camera App
//The widget of video
private VideoView videoView;
//current pos of the video file
private static int currentPosition = 0;
//video URI

private Uri videoUri;

publicvoid onCreate(Bundle savedInstanceState) {
Log.d(TAG, "entering the onCreate..."); super.onCreate(savedInstanceState); setContentView(R.layout.video_camera);
videoView = (VideoView) findViewById(R.id.video_window); Button vidBtn = (Button) findViewById(R.id.video_start); setBtnListenerOrDisable(vidBtn, mTakeVidOnClickListener,MediaStore.ACTION_VIDEO_CAPTURE); MediaController controller = new MediaController(this); videoView.setMediaController(controller); videoView.setOnPreparedListener(new OnPreparedListener() { public void onPrepared(MediaPlayer mp) { videoView.setBackgroundColor(Color.argb(0, 0, 255, 0)); } });
videoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) { Toast.makeText(VideoCameraActivity.this, "The End.",Toast.LENGTH_LONG).show(); } });

}

Send the intent to the camcorder, and prepare and bind the MediaController to the videoView.


View the Video
protectedvoid onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) { Log.d(TAG, "entering the call back..."); videoUri = data.getData(); videoView.setVideoURI(videoUri); videoView.requestFocus(); }
}

That is the callback method of the camcorder application.

Other state and restate method
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d(TAG, "entering the onKeyDown..."); if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { finish(); return true; } return false; }
Button.OnClickListener mTakeVidOnClickListener = new Button.OnClickListener() { public void onClick(View v) { Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); startActivityForResult(takeVideoIntent, VIDEO_REQUEST); } };
protected void onSaveInstanceState(Bundle outState) { Log.d(TAG, "entering the onSaveInstanceState..."); outState.putParcelable(VIDEO_STORAGE_KEY, videoUri); super.onSaveInstanceState(outState); }
protected void onRestoreInstanceState(Bundle savedInstanceState) { Log.d(TAG, "entering the onRestoreInstanceState..."); super.onRestoreInstanceState(savedInstanceState); videoUri = savedInstanceState.getParcelable(VIDEO_STORAGE_KEY); videoView.setVideoURI(videoUri);
//videoView.setVideoPath(URL of the video file) videoView.requestFocus();

}

That is it, a simple video demo. videoView.setVideoPath(URL_PATH). Maybe in the future, I need this statement.

References:
http://developer.android.com/training/camera/videobasics.html

customer android player
http://www.360doc.com/content/11/0309/11/474846_99476781.shtml
http://easymorse.googlecode.com/svn/trunk/
http://easymorse.googlecode.com/svn/trunk/android.customer.player/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值