ITeye博客

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

sillycat · 2013-04-10 22:53 · Mobile Platform · 移动开发 · Markdown

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

  1. 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)

暂无评论。

评论功能维护中,当前仅展示历史评论。