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
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.
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.
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...)
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.
You can view your own video by creating a folder under res
as follows:
res
-> New
-> Android Resource Directory
raw
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With