简体   繁体   中英

blank screen appears before video is started playing android

In my android app Ads are there which are like 20 sec after ads get finished the video which user wants to play is started but blank screen is appear for few minutes.

After click on button in my activity the ads will be displayed as ads finished the video is displayed.My problem is that as soon as ads are finished then blank screen appear I think android is trying to buffer that video. I want to show some notification like progress bar/alert dialog telling the user that something is happening now since blank screen is appears user we feel nothing is happening. But I am not able to identify the point at which I should put notification. It depends on internet speed that video buffering.

Create an inner class inside your activity that extends AsynTask.

For eg:

private class ShowVideoTask extends AsyncTask<String, Void, Boolean> {

boolean success = false;

@Override
    protected void onPreExecute() {
        super.onPreExecute();
        // show a progress dialog indicating that its loading
    }

    @Override
    protected Boolean doInBackground(String... params) {
            // give your code that has to be loaded.
            // after you load video give success = true;
    }

    @Override
    protected void onPostExecute(Boolean success) {
        super.onPostExecute(success);

        if(success) {
            //dismiss your progress dialog 
        }
    }
 }

And inside your onCreate() call this class as:

new ShowVideoTask().execute();

By doing this the doInBackground() gets called. So your video gets played if u give that in this method.

Give progress dialog inside onPreExecute() and dismiss dialog in onPostExecute() . So while method inside doInbackground() is executing, this progress dialog gets displayed and when its over, onPostExecute() gets called.

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