11

I have a video, I need to know where to place and how to get the path of that video.

I know how to add the video form URL,

 Uri uri=Uri.parse("www.abc.com/myVid.mp4");
        videoView = (VideoView) findViewById(R.id.videoView);
        videoView.setVideoURI(uri);

This works fine, but now the video file is in my project, I need to know how to get the path from the folder structure

Kindly guide me.

Thanks

dev90
  • 7,187
  • 15
  • 80
  • 153

4 Answers4

15

You can create asset folder inside your project and store your video in that folder.

Then you can get that using getAssets() function which is provided by Android.

EDIT 1:

You can click on the Project window, press Alt-Insert, and select Folder -> Assets Folder. Android Studio will add it automatically to the correct location.

Also, you can do this.

VideoView view = (VideoView)findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
view.setVideoURI(Uri.parse(path));
view.start();

Where video_file is your file name.

Jaydev
  • 1,794
  • 20
  • 37
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
9

You can Create a folder under Resources and Name it raw. Then to provide the Path to the Video you can simply do

 String path = "android.resource://" + getPackageName() + "/"
            + R.raw.intro_land;

and then

  videoplayer.setVideoURI(Uri.parse(path));
Umer Kiani
  • 3,783
  • 5
  • 36
  • 63
4

You can view your own video by creating a folder under res as follows:

  • Right click on res -> New -> Android Resource Directory
  • select Resource type as raw

New Resource Directory

Then you can upload your video into this directory.

VideoView videoView = videoViewFragment.findViewById(R.id.videoView);
String path = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.video01;
herevideoView.setVideoURI(Uri.parse(path)); 
videoView.start();

video01 is your mp4 file name

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
1

You can create raw folder under res and put your video there,

Check this

VideoView mVideoView = (VideoView)findViewById(R.id.videoview);

                    String uriPath = "android.resource://com.android.AndroidVideoPlayer/"+R.raw.k;

                    Uri uri = Uri.parse(uriPath);
                    mVideoView.setVideoURI(uri);
                    mVideoView.requestFocus();
                    mVideoView.start();
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96