将启动画面 img 更改为 mp4

Change the splash screen img to mp4

我想将我的应用程序中的启动画面从 img 更改为 mp4,但是当我 运行 应用程序看到黑屏时出现问题。

问题是什么?

public class SplashActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new Handler().postDelayed(new Runnable(){
      @Override
      public void run() {
                /* Create an Intent that will start the Menu-Activity. */
        Intent mainIntent = new Intent(SplashActivity.this , QuranDataActivity.class);
        SplashActivity.this.startActivity(mainIntent);
        SplashActivity.this.finish();
      }
    }, 4000);

  }

}

您可以使用 VideoView 只需将其添加到您的 SplashScreenActivity 布局 xml 中,然后以编程方式在其中播放视频。

public class SplashActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_splash);

     // For playing Video
     VideoView view = (VideoView)findViewById(R.id.videoView);
     String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
     view.setMediaController(null); // to hide the controllers
     view.setVideoURI(Uri.parse(path));
     view.start();         

     new Handler().postDelayed(new Runnable(){
      @Override
      public void run() {
               /* Create an Intent that will start the Menu-Activity. */
           Intent mainIntent = new Intent(SplashActivity.this , QuranDataActivity.class);
           SplashActivity.this.startActivity(mainIntent);
           SplashActivity.this.finish();
          }
       }, 4000);

   }

 }