2012-04-10 42 views
4

我在我的應用程序中放入了一個videoview,它工作正常,但是當您打開該頁面時,它會永久加載/緩衝。爲什麼videoview如此之慢?

無論如何我可以解決這個問題。我的意思是這是一個3秒視頻。加載不需要很長時間。對?

代碼:

package jslsoftware.co.nr; 

    import android.app.Activity; 

    import android.net.Uri; 
    import android.os.Bundle; 
    import android.widget.VideoView; 
    import android.widget.MediaController; 

    public class videoview1 extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.video1); 

     Uri vidFile = Uri.parse("http://jslserver1.yolasite.com/resources/3gp_videos/Animal.3gp"); 
     VideoView videoView = (VideoView) findViewById(R.id.videoView1); 
     videoView.setVideoURI(vidFile); 
     videoView.setMediaController(new MediaController(this)); 
     videoView.start(); 
    } 
} 

感謝

回答

3

,而不是直接將代碼爲什麼不能繼承呢?

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { 
    protected Bitmap doInBackground(String... urls) { 
     return loadImageFromNetwork(urls[0]); 
    } 

    protected void onPostExecute(Bitmap result) { 
     mImageView.setImageBitmap(result); 
    } 
} 

只需在doInBackground方法內替換你的東西。如果執行後有任何要做的地方放在onPostExecute中。

+0

我閱讀了那個鏈接,並且以不讓事情陷入困境的方式進行了很多探索。但現在我對代碼不太好(剛開始)。你能夠提供給我一些使用單獨線程的代碼,或者給我說明我需要做什麼來將它安裝到我的代碼中。非常感謝你的幫助! – scott1218 2012-04-10 03:49:49

+0

在你的代碼中定義另一個類,並將你的視頻調用放在後臺服務中。我將用代碼編輯我的答案。 – MACMAN 2012-04-10 03:55:11

+0

非常感謝你! – scott1218 2012-04-10 04:05:12