VideoView implements the video welcoming effect on the boot page, which is super simple but extremely cool. videoview is cool.

Source: Internet
Author: User

VideoView implements the video welcoming effect on the boot page, which is super simple but extremely cool. videoview is cool.

Android advanced control (4) -- VideoView achieves video welcoming effect on boot pages, which is super simple but cool

Is it really exciting to update the dazzling boot page of the new version of the QQ space? haha, in fact, it's really easy to implement it, just an official built-in VideoView, however, the official space has the disadvantage that it cannot be full screen. You cannot set match_parent in time, and some mobile phones have black borders. Here we create a raw folder under the res directory, then, we put the video we want to play in. Here we just made a loop of video playback effect. First, we overwrite VideoView and let him fill the screen, this method also shows a teaching video of a website. However, it is not simple to say anything about it. The video materials are also directly used without advertisement ....

CustomVideoView
Package com.lgl.mp4 index; import android. content. context; import android. media. mediaPlayer; import android. util. attributeSet; import android. view. keyEvent; import android. widget. videoView;/*** video playback, mainly because of the large size of the mobile phone, cannot ensure that the native VideoView can achieve full screen * Created by lgl on 16/2/18. */public class CustomVideoView extends VideoView {public CustomVideoView (Context context) {super (context);} public CustomVideoView (Context context, AttributeSet attrs) {super (context, attrs );} public CustomVideoView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle) ;}@ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {// re-calculate the height int width = getDefaultSize (0, widthMeasureSpec); int height = getDefaultSize (0, heightMeasureSpec); setMeasuredDimension (width, height );} @ Override public void setOnPreparedListener (MediaPlayer. onPreparedListener l) {super. setOnPreparedListener (l) ;}@ Override public boolean onKeyDown (int keyCode, KeyEvent event) {return super. onKeyDown (keyCode, event );}}
  • 12345678910111213141516171819202122232425262728293031323334353637383940414243444546
Activity_main.xml
 
     
  
   
    
 
  • 123456789101112131415161718192021
MainActivity
Package com.lgl.mp4 index; import android. media. mediaPlayer; import android.net. uri; import android. support. v7.app. appCompatActivity; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. toast; public class MainActivity extends AppCompatActivity implements View. onClickListener {private CustomVideoView videoview; private Button btn_start; @ Override protected Void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initView ();}/*** initialize */private void initView () {btn_start = (Button) findViewById (R. id. btn_start); btn_start.setOnClickListener (this); videoview = (CustomVideoView) findViewById (R. id. videoview); // sets the playback loading path videoview. setVideoURI (Uri. parse ("android. resource: // "+ getPackageName () + "/" + R. raw. media); // play videoview. start (); // loop playback videoview. setOnCompletionListener (new MediaPlayer. onCompletionListener () {@ Override public void onCompletion (MediaPlayer mediaPlayer) {videoview. start () ;}}) ;}@ Override public void onClick (View view) {switch (view. getId () {case R. id. btn_start: Toast. makeText (this, "Go to the Homepage", Toast. LENGTH_SHORT ). show (); break ;}}} is so simple ..... Don't talk about my post. Let's run it.

The Demo won't be uploaded. That's the 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.