Below is my Code :
package com.example.videoplayer;
import android.app.Activity;
import android.app.ProgressDialog;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoPlayerActivity extends Activity {
String TAG = "com.example.VideoPlayer";
ProgressDialog progDailog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
final VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progDailog.dismiss();
Log.i(TAG, "Duration = " + videoView.getDuration());
}
});
videoView.start();
progDailog = ProgressDialog.show(this, "Please wait ...", "Retrieving data ...", `enter code here`true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.video_player, menu);
return true;
}
}
Check out this :
Play http videos in VideoView
This is my code :
Thanks
Don't do everything in the UI thread because it takes a lot of time. Do everything in
AsyncTask
and things will work out fine.For beginners, this link describes how could you do it in
AsyncTask
.Define a class which extends the
AsyncTask
:Then, in the
onCreate()
method, just call theexecute()
method of thisBackgroundAsynchTask
: