Android的形象时序问题 [英] Android image timing issues

查看:132
本文介绍了Android的形象时序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,需要一个循环来显示图像和视频,它与播放的影片没有问题,但是当它到达图像屏幕变为空白,并没有任何反应。该程序仍在运行,只是没有显示。

I have an Android app that needs to display images and videos in a loop, it has no problem with playing the videos, but when it gets to the images the screen goes blank and nothing happens. the program is still running just not displaying.

我用 SurfaceView.setBackground()来绘制图像,因为ImageView的和SurfaceView该影片在之前已经造成的问题起到之间交换。

I'm using SurfaceView.setBackground() to draw the image because swapping between an ImageView and the SurfaceView that the videos are played on has caused problems before.

我在显示视频时,有一个类似的问题,我通过删除我已经等待视频是ppared所以理论上讲,$ P $我想删除我已经等待计时器的等待循环的循环解决它

I was having a similar issue when displaying the videos and I solved it by removing the loop I had waiting for the video to be prepared so ideally I would like to remove the loop I have waiting for a timer to elapse.

我有一种功能,当旧的完成以显示新的媒体,它也prepares下一个当电流之一完成了。如果媒体是视频这是从工作正常的的onComplete函数调用。但是,如果它是一个像我有一个等待循环。

I have a function to display the new media when the old one is finished and it also prepares the next one for when the current one is finished. If the media is a video this is called from the onComplete function which works fine. But if it is an image I have a wait loop.

我想要做的是有类似的 MediaPlayer.onComplete()当图像已显示所需的时间量来调用。难道这样的事情存在吗?

What I want to do is have something like the MediaPlayer.onComplete() function to be called when the image has been displayed for the desired amount of time. Does anything like this exist?

推荐答案

因为我已经改变了这种使用,因为其他一些错误检查,我需要做的处理程序。然而,另一种方式确实工作

I have since changed this to use handlers because of some other error checking I needed to do. However the other way does work

mHandler.postdelayed(run, delay);

Runnable run = new Runnable(){

      public void run()
       {
          //run function
       }
     };

我想通了。我提出,跑了计时器,并调用在更新屏幕的主要活动功能一个新的线程。该更新屏幕使用 runOnUiThread(),使其有权更改屏幕调用的函数调用。

I figured it out. I made a new thread that ran a timer and calls a function in the main activity that updates the screen. The call to the function that updates the screen is called using runOnUiThread() so that it has permission to change the screen.

public class ImageTimer implements Runnable{


    private long dur, cur,start;
    private boolean needed, run;
    private Activity mAct;

    ImageTimer(boolean running, long duration, Activity act)
    {
        run = running;
        dur = duration;
        needed = false;
        mAct = act;
    }

    @Override
    public void run() 
    {
        while(run)
        {
            if(needed)
            {
                start = System.currentTimeMillis();
                cur = System.currentTimeMillis() - start;
                while(cur < dur)
                {
                    cur = System.currentTimeMillis() - start;
                }   
                needed = false ;
                mAct.runOnUiThread(new Runnable() 
                {
                     public void run() 
                     {

                        MainActivity.ImageDone();
                     }

                });
            }
        }
    }

这篇关于Android的形象时序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆