000000000000000000000
000000000000000000000

Reputation: 1467

Cannot start video player activity

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

Answers (3)

Shadow
Shadow

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

Amarjit
Amarjit

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

user4571931
user4571931

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

Related Questions