Do not do everything in the user interface thread, because it takes a lot of time. Do everything in AsyncTask and everything will be fine.
For beginners, this link describes how you could do this in AsyncTask .
Define a class that extends AsyncTask :
public class BackgroundAsyncTask extends AsyncTask<String, Uri, Void> { Integer track = 0; ProgressDialog dialog; protected void onPreExecute() { dialog = new ProgressDialog(PlayVideo.this); dialog.setMessage("Loading, Please Wait..."); dialog.setCancelable(true); dialog.show(); } protected void onProgressUpdate(final Uri... uri) { try { media=new MediaController(PlayVideo.this); video.setMediaController(media); media.setPrevNextListeners(new View.OnClickListener() { @Override public void onClick(View v) {
Then, in the onCreate() method, just call the execute() method of this BackgroundAsynchTask :
video = (VideoView) findViewById(R.id.video); new BackgroundAsyncTask().execute("link-to-the-video");
Akeshwar jha
source share