Video Player


Video Player

Unlike in audio players, here we use VideoView factor and MediaController class for the same actions that were discussed in audio player.  

The VideoView brings the video in the app and plays them, MediaController is responisible for the playback options.  

Make an android application and use names like VideoPlayerExample. By making a raw folder in res directory, you can add any video file.

Code 

activity_main.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"     android:paddingLeft="10dp"     android:paddingRight="10dp">     <VideoView         android:id="@+id/vdVw"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_gravity="center" /> </RelativeLayout> In the main activity file, from \java\com.tutlane.videoplayerexample path, open MainActivity.java, type the code that is written below: MainActivity.java package com.tutlane.videoplayerexample; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends AppCompatActivity {     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         VideoView videoView =(VideoView)findViewById(R.id.vdVw);         //Set MediaController  to enable play, pause, forward, etc options.         MediaController mediaController= new MediaController(this);         mediaController.setAnchorView(videoView);         //Location of Media File         Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video1);         //Starting VideView By Setting MediaController and URI         videoView.setMediaController(mediaController);         videoView.setVideoURI(uri);         videoView.requestFocus();         videoView.start();     } }

Image

Image Not Found