Load video file from local file system : Video « Media « Android






Load video file from local file system

  

package app.test;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.setContentView(R.layout.main);

      VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
      MediaController mc = new MediaController(this);
      videoView.setMediaController(mc);

        videoView.setVideoPath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) +"/movie.mp4");

 
      videoView.requestFocus();
      videoView.start();
  }
}

//main.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- This file is /res/layout/main.xml -->
<LinearLayout
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">
   <VideoView  android:id="@+id/videoView"
      android:layout_width="190px"  android:layout_height="wrap_content"
    />
</LinearLayout>

   
    
  








Related examples in the same category

1.Record video
2.Capture Video
3.Store image and video
4.Uri for local video file
5.Custom Video Player
6.Get Video size
7.Display video with VideoView
8.Using MediaController to control Video
9.Play video from Youtube.com
10.Video Gallery
11.View Video with VideoView
12.Video Capture
13.Video Capture with Metadata
14.VideoView Demo