Why is the videoview so slow?

别说谁变了你拦得住时间么 提交于 2020-01-03 15:32:18

问题


I put a videoview in my application and it works fine but when you open up the page it take forever for it to load/buffer.

Is there anyway I can fix this. I mean it's a 3 second video. It shouldn't take a long time to load. Right?

code:

 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();
    }
}

Thanks


回答1:


Instead of directly placing the code why not subclass it?

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);
    }
}

Just replace your stuff inside doInBackground method. If you have anything to do after it's executed place in onPostExecute.



来源:https://stackoverflow.com/questions/10082728/why-is-the-videoview-so-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!