Play Video in Android using full screen(.mp4,.ts...etc)

video.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
<VideoView
    android:id="@+id/video"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
     android:layout_alignParentBottom="true"
            />

</RelativeLayout>





videoplayer.java

public class videoplayer extends Activity {

 private static String path ="https://vimeoassets-ireland.s3-eu-west-1.amazonaws.com/1367/EncodedVideo/uploads/movie_stream/full_movie/25954/small.mp4";
 private static String path1 ="http://iptv.am000.tv:8000/live/saleemhome/saleemhome/2.ts";

private VideoView mVideo;
private MediaController ctlr;
 private ProgressDialog pDialog;
  Context ctx;
@Override
public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.playvideo1);
        ctx=this;
        
        mVideo = (VideoView) findViewById(R.id.video);
 
// Create a progressbar
pDialog = new ProgressDialog(PlayVideo1.this);
 
// Set progressbar message
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();
 
try {
// Start the MediaController
MediaController controller = new MediaController(this);

mVideo.setMediaController(controller);
mVideo.setVideoURI(Uri.parse(path)); //  you can chnage url from here
 
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
 
mVideo.requestFocus();
mVideo.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
mVideo.start();
}
});
 }
 @Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
mVideo.stopPlayback();
finish();
}







Comments