MainActivity is as follows:
Package C. c; import android. app. activity; import android. content. contentvalues; import android. content. intent; 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. edittext;/*** demo Description: * 1. Use the System camera to take a video. * 2. Use the system control to play the video. * 3. Modify the video metadata (for example, video title). ** note: * When the metadata is updated in mediastore, the * Data of the video file itself is not updated; instead, it only updates the record about the video in mediastore */public class mainactivity extends activity {private final static int video_capture = 9527; private URI mvideouri; private button mcapturebutton; private button mplaybutton; private button msavebutton; private edittext medittext; @ 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 (); msavebutton = (button) findviewbyid (R. id. save_button); msavebutton. setonclicklistener (New buttonclicklistenerimpl (); msavebutton. setenabled (false); medittext = (edittext) findviewbyid (R. id. edittext); medittext. setenabled (false);} private class buttonclicklistenerimpl implements onclicklistener {public void onclick (view v) {If (v. GETID () = R. id. capture_button) {intent = new intent (mediastore. action_video_capture); startactivityforresult (intent, video_capture);} If (v. GETID () = R. id. play_button) {intent = new intent (intent. action_view, mvideouri); startactivity (intent);} If (v. GETID () = R. id. save_button) {contentvalues = new contentvalues (1); String title = medittext. gettext (). tostring (); contentvalues. put (mediastore. mediacolumns. title, title); int result = getcontentresolver (). update (mvideouri, contentvalues, null, null); If (result = 1) {system. out. println ("video name set successfully");} else {system. out. println ("failed to set video name") ;}}@ 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); msavebutton. setenabled (true); medittext. 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" /> <EditText android:id="@+id/editText" android:layout_width="150dip" android:layout_height="wrap_content" android:hint="video title" /> <Button android:id="@+id/save_Button" android:layout_width="150dip" android:layout_height="wrap_content" android:text="save Button" /> </LinearLayout>