Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put the Video file in android Project

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

like image 566
dev90 Avatar asked Jul 27 '16 12:07

dev90


People also ask

Where do Android Studio projects save?

Android Studio stores the projects by default in the home folder of the user under AndroidStudioProjects. The main directory contains configuration files for Android Studio and the Gradle build files. The application relevant files are contained in the app folder.

What folder are important in Android project?

The resource folder is the most important folder because it contains all the non-code sources like images, XML layouts, and UI strings for our android application.

What is the use of video view?

VideoView is a custommized component which is available of Android, it is the combination of MediaPlayer and SuffaceView which help you to play a video more easily. When using VideoView, you can use MediaController, this is available in Android which used to control media (such as start, stop, rewind, pause...)


2 Answers

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.

like image 53
Jay Rathod RJ Avatar answered Nov 16 '22 01:11

Jay Rathod RJ


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

like image 40
Prabhashani Avatar answered Nov 16 '22 01:11

Prabhashani