简体   繁体   中英

Playing movie at app starting

I would like to play a movie at the begning of my Android application. So I use this code but it generates this error :

android.view.WindowLeaked:MainActivity has leaked window com.android.internal.policy

public class MainActivity extends AppCompatActivity {

private static int TIME_OUT = 8000;
String SrcPath = "android.resource://com.appdev.loicomelectronique/debut";
VideoView video;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(1);
    getWindow().setFlags(1024, 1024);
    setContentView(R.layout.activity_main);

    video = (VideoView)findViewById(R.id.videoView);
    video.setVideoURI(Uri.parse(this.SrcPath));
    video.requestFocus();
    video.start();
    new Handler().postDelayed(new Runnable()
    {
        public void run()
        {
            Intent localIntent = new Intent(MainActivity.this, MainActivityLoi.class);
            startActivity(localIntent);
            //MainActivity.this.finish();
        }
    }, TIME_OUT);
}

}

Please how can I fix it. All I found on web are about displaying a Dialog but in my case it is a video.

Thanks

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(1); getWindow().setFlags(1024, 1024); setContentView(R.layout.activity_main); video = (VideoView)findViewById(R.id.videoView); video.setVideoURI(Uri.parse(this.SrcPath)); video.requestFocus(); video.start(); mHandler=new Handler(); mRunable=new Runable() { public void run() { Intent localIntent = new Intent(MainActivity.this, MainActivityLoi.class); startActivity(localIntent); //MainActivity.this.finish(); } }; mhandler.postDelayed(mRunnable,TIME_OUT); } @Override protected void onStop() { if(mHandler!=null){ if(mHandler!=null){ mHandler.removeCallbacks(mRunnable); } mHandler==null; } super.onStop(); } 

Here is my layout.xml file

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.appdev.loicomelectronique.activities.MainActivity">

<VideoView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/videoView"/>

 </FrameLayout>

I don't specify a dimension for video, just the layout and my .mp4 video file Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM