Reputation: 1467
I have a video in my /res/raw/
folder and I would like to start it using the native video player of the device.
This is my code:
String packageName = this.getPackageName();
Uri uri = Uri.parse("android.resource://" + packageName + "/raw/" + R.raw.my_video);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);
When I trie to start the video it crashes and I get this error in LogCat:
09-16 15:05:51.959: E/AndroidRuntime(23298): FATAL EXCEPTION: main 09-16 15:05:51.959: E/AndroidRuntime(23298): java.lang.IllegalStateException: Could not execute method of the activity
I tried Uri.parse(String)
on a hosted mp4-file from a random webpage with the same result.
What is my problem?
Upvotes: 0
Views: 81
Reputation: 6899
Issue is you are using wrong raw folder name.
Uri uri = Uri.parse("android.resource://" + packageName + "/raw/" + R.raw.my_video);
Remove and use like this.
Uri uri = Uri.parse("android.resource://" + packageName + "/" + R.raw.my_video);
Upvotes: 3
Reputation: 4357
you add /raw
extra in your URI path , Please make it
Uri uri = Uri.parse("android.resource://" + packageName + "/" + R.raw.my_video);
Upvotes: 0
Reputation:
Hi please try below code hope it will help you
Uri intentUri = Uri.parse("android.resource://"+ packageName + "/" + R.raw.my_video);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(intentUri, "video/mp4");
startActivity(intent);
Upvotes: 0