I created the raw resources directory and inserted the video test.mp4 into it.
I am try to run the following code but it is giving me an unresolved reference on test
val uri = Uri.parse("android.resource://" + packageName + "/" + R.raw.test)
videoview.setVideoURI(uri)
videoview.setOnPreparedListener { videoview.start() }
Related
I have the following code
val path = "android.resource://" + activity?.packageName + "/" + R.raw.body_video
val uri = Uri.parse(path)
videoView.setVideoURI(uri)
videoView.start()
but on loading the view i get this
The path all seems to be correct, so im unsure what could be wrong. This asset works on our iOS app so the file is ok
The way you are getting the id from resource folder (raw) is wrong. Try will following code it will work.
In Java
// To get files from any resource folder (eg: raw, drawable, etc.)
// Use the resource id
int rawId = getResources().getIdentifier(file_name_without_extension, "raw", getPackageName());
// URI formation
String path = "android.resource://" + getPackageName() + "/" + rawId;
// Set the URI to play video file
videoView.setVideoURI(Uri.parse(path));
videoView.start()
Kotlin Activity
// To get files from any resource folder (eg: raw, drawable, etc.)
//Use the resource id
val rawId = resources.getIdentifier(file_name_without_extension, "raw", packageName)
// URI formation
val path = "android.resource://$packageName/$rawId"
// Set the URI to play video file
videoView.setVideoURI(Uri.parse(path))
videoView.start()
Kotlin Fragment #Update
// To get files from any resource folder (eg: raw, drawable, etc.) Use the resource id
val packageNameValue = activity!!.packageName
val rawId = activity!!.resources.getIdentifier(file_name_without_extension, "raw", packageNameValue)
// URI formation
val path = "android.resource://$packageNameValue/$rawId"
// Set the URI to play video file
videoView.setVideoURI(Uri.parse(path))
videoView.start()
I have a .txt file inside my raw folder. I want to get the uri of the file and create a new file to upload to firebase.
The idea is simple
Get the txt file from my res/raw resources
Upload it to firebase storage
I have done this
String path = "android.resource://" + getPackageName() + "/" + "raw/grupos.txt";
Uri file = Uri.fromFile(new File(path));
but when I call
riversRef.putFile(file)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {....
it says that the file is invalid
LOGCAT
java.io.FileNotFoundException:
/android.resource:/com.example.usuario.ottasubirarchivos/raw/grupos.txt:
open failed: ENOENT (No such file or directory)
I don't know if I need to get the path of the resource file, create a new file inside the internal storage, get that file and upload it to firebase, or either use stream... I don't know how to handle this... Thanks
You could use this:
public class UriUtils {
public static Uri getUriToResource(#NonNull Context context, #AnyRes int resId) throws Resources.NotFoundException {
Resources res = context.getResources();
Uri resUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + res.getResourcePackageName(resId)
+ '/' + res.getResourceTypeName(resId)
+ '/' + res.getResourceEntryName(resId));
return resUri;
}
}
Do you have this working?
I can access a raw resource this way: Android.Net.Uri.Parse("android.resource://" + ApplicationContext.PackageName + "/" + Resource.Raw.beep)
With the file beep.ogg located under Resources/raw directory. What I've noticed here are: the capital letter in Raw, Resource and not ResourceS and the extensionless filename in my path. As noted by CommonsWare in comments you don't have a file but its Uri so parse it directly
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
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 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));
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
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
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();
This is Success.
notificationBuilder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/raw/testfile"));
However, in the following way is Not Work.
notificationBuilder.setSound(Uri.parse("file:///data/data/com.Company.test/files/testfile.wav"));
File outFile = new File("/data/data/com.Company.test/files/testfile.wav");
outFile.exists() == true
File exists.
Why ?
Put your file in raw folder
and give uri path
Uri path = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.testfile);
i have a strange behavior while coding a video player. I have an html5 menu that targets mp4 videos. When you click on a video, the path will be treated and a native video player intent will start to play the video. My videos are placed in "raw" folder.
When I use a static path, the video plays very well:
String uriPath = "android.resource://" + getPackageName() + "/" + R.raw.video1;
When I use the following path, I can't play it:
video_title = getIntent().getExtras().getString("video_title");
String uriPath = "android.resource://" + getPackageName() + "/" + "R.raw."+video_title;
Note that i removed the extension of the file in the main intent so the variable "video_title" will hold the video title without extension.
I resolved this issue, by changing the uriPath variable:
String uriPath = "android.resource://" + getPackageName() + "/" + "R.raw."+video_title; // BAD
String uriPath = "android.resource://" + getPackageName() + "/" + "raw/"+video_title; // GOOD