简体   繁体   English

视频开始播放android之前出现空白屏幕

[英]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. 在我的android应用中,广告出现了,广告完成后大约有20秒,用户想要播放的视频开始播放,但几分钟后出现黑屏。

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. 在我的活动中单击按钮后,广告将显示为广告完成,视频显示完毕。我的问题是,广告完成后,出现黑屏,我认为android正在尝试缓冲该视频。 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. 在您的活动内创建一个扩展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: 在您的onCreate()内部,将该类称为:

new ShowVideoTask().execute();

By doing this the doInBackground() gets called. 通过这样做, doInBackground()被调用。 So your video gets played if u give that in this method. 因此,如果您通过这种方法提供视频,那么您的视频就会播放。

Give progress dialog inside onPreExecute() and dismiss dialog in onPostExecute() . 给进度对话框内onPreExecute()和解雇对话框onPostExecute() So while method inside doInbackground() is executing, this progress dialog gets displayed and when its over, onPostExecute() gets called. 因此,在执行doInbackground()内部的方法时,将显示此进度对话框,并在结束时调用onPostExecute()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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