Video as a Splash Screen instead of Picture

前端 未结 5 1538
天命终不由人
天命终不由人 2020-12-13 15:43

I am doing the Android Programming Tutorial on Splash Screens where you show a picture or text for 5 Seconds than it goes to the Main Application. My Question is..Instead of

5条回答
  •  温柔的废话
    2020-12-13 16:00

    Here is the code for adding video. In case you need to add controls on video like pause or seek etc. you can add them with:

    vv.setMediaController(new MediaController(this));
    

    Rest of the code:

    VideoView vv;
    
    @Override
    
    protected void onCreate(Bundle savedInstanceState)
    
    {
    
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.activity_splash);
    
        vv=(VideoView)findViewById(R.id.videoView);
        Uri path=Uri.parse("android:resource://"+getPackageName()+"/"+R.raw.hello);
        vv.setVideoURI(path);
        vv.setMediaController(new MediaController(this));
    
       vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
       {
           @Override
           public void onCompletion(MediaPlayer mp) {
               Intent in=new Intent(splash.this,MainActivity.class);
            startActivity(in);
               finish();
    
           }
       });
        vv.start();
    

提交回复
热议问题