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/

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android 启动Service监听网络状态
  2. kotlin 写的Android(安卓)toast工具类
  3. Android中应用调用系统权限
  4. Android 第十七天
  5. 我学习Android的一些套路
  6. Android之MTP框架和流程分析
  7. Android四大组件之Content Provider
  8. Java 字节码编译为Dex,d8比dx更好用!
  9. Android程序开机启动&&监听情景模式切换
  10. Android清单文件详解(六) ---- 节点的属