MainActivity is as follows:
Package c. c; import android.net. uri; import android. OS. bundle; import android. provider. mediaStore; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. videoView; import android. app. activity; import android. content. intent;/*** Demo Description: * use the System camera to take a video and use the VideoView control to play the video */public class MainActivity extends Activity {private final static int VIDEO_CAPTURE = 9527; private Uri mVideoUri; private Button mCaptureButton; private Button mPlayButton; private VideoView mVideoView; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mCaptureButton = (Button) findViewById (R. id. capture_Button); mCaptureButton. setOnClickListener (new ButtonClickListenerImpl (); mPlayButton = (Button) findViewById (R. id. play_Button); mPlayButton. setEnabled (false); mPlayButton. setOnClickListener (new ButtonClickListenerImpl (); mVideoView = (VideoView) findViewById (R. id. videoView);} private class ButtonClickListenerImpl implements OnClickListener {public void onClick (View v) {if (v. getId () = R. id. capture_Button) {Intent intent = new Intent (MediaStore. ACTION_VIDEO_CAPTURE); startActivityForResult (intent, VIDEO_CAPTURE);} else {mVideoView. setVideoURI (mVideoUri); mVideoView. start () ;}}@ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {super. onActivityResult (requestCode, resultCode, data); if (resultCode = RESULT_ OK & requestCode = VIDEO_CAPTURE) {mVideoUri = data. getData (); mPlayButton. setEnabled (true );}}}
Main. xml is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/capture_Button" android:layout_width="150dip" android:layout_height="wrap_content" android:text="Video Capture" /> <Button android:id="@+id/play_Button" android:layout_width="150dip" android:layout_height="wrap_content" android:text="Video Play" /> <VideoView android:id="@+id/videoView" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>