Do the project need to play a boot video, this thought is very simple, the results found there is always a flaw, fortunately there are degrees Niang, now the harvest summarized as follows:
First, to achieve video playback:
Note that I am here to play a resource file in an Android project instead of accessing the SD card to play the video.
1. First put the video you want to play in the Res/raw directory
2. The video format must be Android-supported format (3GP,MP4,WMV), which is said to be unsupported by SWF and has not been tried. And the video file name cannot have capital letters, it must be lowercase letters, numbers, or underscores.
3. Add the Videoview component to the layout file
4. Create a String type object to save the URI
5. Call Videoview's Setvideouri method to set the URI, which is the URI above
6. Call the start () method to play.
The code is as follows:
The layout file is added:
<videoview android:id= "@+id/video" android:layout_width= "match_parent" android:layout_height= " Match_parent "/>
Asettings in ctivity:
private void PlayVideo () {video = (videoview) Findviewbyid (R.id.video); String uri = "android.resource://" + getpackagename () + "/" + R.raw.guide;video.setvideouri (Uri.parse (URI)); Video.start ();}
The above code to achieve the video playback, but the video is not as we want to horizontal screen, full-screen playback, so we need a second step:
Second, the video full-screen playback (remove the bottom of the border appears):
If you want to configure Videoview, you need to use the Setlayoutparams method. But looking at the API we can see that Videoview does not have this method, how to do?
We need to wrap a layout outside of the Videoview component in the layout file, I use relativelayout here, and the rest should also be:
<relativelayout android:layout_width= "match_parent" android:layout_height= "match_parent" > <videoview android:id= "@+id/video" android:layout_width= "match_parent" android:layout_height= " Match_parent "/> </RelativeLayout>
once added, you can configure the parameters:
String uri = "android.resource://" + getpackagename () + "/" + R.raw.guide;video.setvideouri (Uri.parse (URI)); Relativelayout.layoutparams layoutparams = new Relativelayout.layoutparams (RelativeLayout.LayoutParams.FILL_PARENT , RelativeLayout.LayoutParams.FILL_PARENT); Layoutparams.addrule (Relativelayout.align_parent_bottom); Layoutparams.addrule (Relativelayout.align_parent_top); Layoutparams.addrule (Relativelayout.align_parent_left); Layoutparams.addrule (relativelayout.align_parent_right); Video.setlayoutparams (layoutparams); Video.start ();
thatfour addrule methods to eliminate the border, Layoutparams construction method to achieve full screen.
After the completion of the previous step to run, found that although the video can be full screen, but the display is completely distorted, not the effect we want, if the mobile phone turned on the auto-turn screen, we will find the mobile phone to the horizontal screen after the video playback effect is what we want. How do I get the video to go to the horizontal screen when it plays?
Three, set the video screen playback:
Each activity allows the screen to be turned on, whether the current display is a horizontal or vertical screen, and can be set by the Androidmanifest.xml file:
For example, when I play a video in splash this activity, you can add the Screenorientation property to her tab to control the screen orientation (Landscape is landscape, portrait is portrait):
<activity android:name= "Com.zsx.activity.Splash" android:label= "@string/app_name" android:theme = "@android: Style/theme.black.notitlebar.fullscreen" android:screenorientation= "Landscape" > </ Activity>
Sometimes we want some pages only vertical screen or horizontal screen, worry about the layout will become ugly after the switch, you can set this property in the activity of the response, the user how to turn the screen will not change! Ha ha
Android Development uses Videoview to achieve horizontal screen playback and remove borders for video