Android video recording with Intent

Source: Internet
Author: User

This article mainly uses the intent to trigger the built-in Camera application to record videos.

Source code:

Layout file:

Activity_main:

     
      
      
  
 


Code file:

MainActivity:

Package com. multimediademo14intentcamera; import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. videoView;/*** use intent to record video **/public class MainActivity extends Activity implements OnClickListener {public static int VIDEO_CAPTURED = 1; /*** Two buttons: video recording Button and video playback Button */private Button button_capture, button_play; private VideoView videoView; private Uri videoFileUri; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); button_capture = (Button) findViewById (R. id. button_capture); button_play = (Button) findViewById (R. id. button_play); videoView = (VideoView) fin DViewById (R. id. videoView); listener (this); button_play.setOnClickListener (this); button_play.setEnabled (false) ;}@ Overridepublic void onClick (View v) {if (v = button_capture) {/*** the video recording button of the store, which passes the creation intent together with the VIDEO_CAPTURED constant to the startActivityForResult method. * This starts the built-in Camera application. */Intent captureVideoIntent = new Intent (android. provider. mediaStore. ACTION_VIDEO_CAPTURE); startActivityForResult (captureVideoIntent, VIDEO_CAPTURED);} else if (v = button_play) {videoView. setVideoURI (videoFileUri); videoView. start () ;}}/*** when the Camera application returns, the following onActivityResult method is called. It checks whether the resultCode is the constant RESULT_ OK, * and whether the requestCode is the value passed into startActivityForResult VIDEO_CAPTURED *, and then obtains the Uri of the recorded video file. * // @ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {if (resultCode = RESULT_ OK & requestCode = VIDEO_CAPTURED) {videoFileUri = data. getData (); button_play.setEnabled (true );}}}


Source code download:

Click to download source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.