2014-05-12 12 views
0

我正在使用Picasso Library從服務器加載圖像。我想每秒鐘更新圖像5-10次。它甚至不加載1幀/秒如何經常從服務器更新ImageView?

 protected String doInBackground(String... data) { 
     while (refreshImage) { 

      runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 

       new Handler().postDelayed(new Runnable() { 
        @Override 
        public void run() { 
        Picasso.with(getApplicationContext()) 
        .load(getImageURL).into(videoImage); 
        } 
        }, 1000); 


       } 
      }); 
     } 

     return null; 
    } 

是否有任何其他方式來更新一個快速幀速率的ImageView?

+0

不getImageURL變化呢? – Egor

+0

沒有。服務器爲getImageURL生成10張圖像/秒 – FilipLuch

回答

0

請嘗試以該速率以下線程功能

new Thread(new Runnable() { 
    @Override 
    public void run() { 
     while (true) { 
      if (Chcek online condition here) { 
       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
         //Do your task here... 
        } 
       }); 
      } 
      try { 
       Thread.sleep(1000); 
      } catch (Exception e) { 
      } 
     } 
    } 
}).start(); 
+0

我已經在doInBackground方法中插入了它,但它不刷新圖像,我只是通常得到第一張圖像。也許有一個圖書館或其他類型的觀點?如果試圖在webView中輸出圖像並以我需要的速度刷新呢? – FilipLuch