Today I learned how to embed a video into an application using the Videoview class, as shown in the following code.
1 Public classTestvideoextendsactionbaractivity {2 3 @Override4 protected voidonCreate (Bundle savedinstancestate) {5 Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_test_video);7 8Videoview video =(Videoview) Findviewbyid (r.id.video);9Video.setvideouri (Uri.parse ("android.resource://com.example.gboy.testvideo/" +r.raw.video));Ten //Android:resource://is fixed, com.example.gboy.testvideo is my package name, R.raw.vedio is a video file in Res/raw video.mp4 One Video.start (); A } -}
XML file:
<framelayout 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" > <videoview android:id= "@+id/video" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_gravity= " Center "/> </FrameLayout>
Android Learning play Video