Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to play video from raw folder (VideoView)

Tags:

android

I can play a video from the Internet by inserting the URL like below:

mPath   = Uri.parse("http://commonsware.com/misc/test2.3gp");
mVid.setVideoURI(mPath);
mVid.requestFocus();
mVid.start();

But now I have a video in my raw folder so the path is res/raw/testing.3gp. The code below doesn't work, and I've tried some other ways too to no avail.

mPath   = Uri.parse("../../res/raw/testing.3gp");

Any suggestions?

like image 987
taraloca Avatar asked Aug 31 '10 12:08

taraloca


People also ask

How do I play a raw video folder?

Create raw folder under res folder. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename likewise:video_file. mp4. VideoView view = (VideoView)findViewById(R.

How to add video in raw folder in android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Create a new android resource folder(raw) and copy-paste your video file in that folder.

How can I open raw folder in Android Studio?

Step 2: Open your android studio go to the app > res > right-click > New > Android Resource Directory as shown in the below image. Step 3: Then a pop-up screen will arise like below. Here in Resource type choose raw.

How do I make Android videos full screen?

Tap the video you'd like to watch. At the bottom of the video player, tap full screen .


2 Answers

I had the same problem. This worked for me:

Uri video = Uri.parse("android.resource://com.pac.myapp/raw/master");

So as you see you have 3 parts of the uri: 1) "android.resource://" 2) "com.pac.myapp" 3) "/raw/master"

"master" is the name of your video

like image 141
Alex Bush Avatar answered Oct 17 '22 14:10

Alex Bush


this works for me

 String videoName = nameWithoutFileExtention;

 int id = getResources().getIdentifier(videoName, "raw", getActivity().getPackageName());

 final String path = "android.resource://" + getActivity().getPackageName() + "/" + id;

 vvBgVideo.setVideoURI(Uri.parse(path));
like image 39
3akat Avatar answered Oct 17 '22 15:10

3akat