问题
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