I am playing an stream from Internet and because long processes such as network operation should not be handled on UI Thread, I'm using AsyncTask. In Main Thread I set some specification of videoView:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
progressDialog = ProgressDialog.show(this, "Loading", "Please Wait", true, true);
videoView = (VideoView) findViewById(R.id.surface_view);
videoView.setVideoPath(ChannelPath);
videoView.setMediaController(new MediaController(this));
new LoadStream().execute("");
}
And in AsyncTask I start the video:
private class LoadStream extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... urls) {
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoView.start();
progressDialog.dismiss();
}
});
return null;
}
}
I tried to have all the parts related to videoView on AsyncTask but was unable to setVideoPath and setMediaController on AsyncTask. I am wondering which part is exactly the time consuming part? Is my code alright? or I'm still having the long process on UI Thread?