I have been trying to get my local videos (raw folder) to run using Intent.ActionView. When I create the Intent and set a data and type then start the activity I get a error. Please look at the following code & error.
I have tried a load of different ways to get to the file thinking maybe it is not being found but I don't think that is the problem. I have tried different video formats but also I do not think that is the problem.
If I use a URL to a MP4 inside SetDataAndType that will run without an error. Maybe this is a permissions error? At this point I really have no idea. I hope someone will be able to explain the problem I an running into here.
Code:
// Create the intent and push the mp4 to it, lets run a video!
Intent videoIntent = new Intent (Intent.ActionView);
// Video is MP4 format
videoIntent.SetDataAndType (Uri.Parse ("android.resource://" + PackageName + "/raw/bunny"), "video/*");
// Crash here, Error: Android.Content.ActivityNotFoundExeception
StartActivity (videoIntent);
Error:
Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.test.videotest/raw/bunny typ=video/* }
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.Content.ContextWrapper.StartActivity (Android.Content.Intent intent) [0x00070] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Content.ContextWrapper.cs:3238
at VideoTest.MainActivity.<OnCreate>m__0 (System.Object , System.EventArgs ) [0x00034] in /Users/alex/Projects/VideoTest/VideoTest/MainActivity.cs:33
at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x0000d] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.View.cs:1780
at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Views.View.cs:1745
at at (wrapper dynamic-method) System.Object:123eb72a-af75-42a8-b3aa-717e415176e4 (intptr,intptr,intptr)
at --- End of managed exception stack trace ---
at android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.test.videotest/raw/bunny typ=video/* }
at at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at at android.app.Activity.startActivityForResult(Activity.java:3930)
at at android.app.Activity.startActivityForResult(Activity.java:3890)
at at android.app.Activity.startActivity(Activity.java:4213)
at at android.app.Activity.startActivity(Activity.java:4181)
at at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
at at android.view.View.performClick(View.java:5204)
at at android.view.View$PerformClick.run(View.java:21155)
at at android.os.Handler.handleCallback(Handler.java:739)
at at android.os.Handler.dispatchMessage(Handler.java:95)
at at android.os.Looper.loop(Looper.java:148)
at at android.app.ActivityThread.main(ActivityThread.java:5422)
at at java.lang.reflect.Method.invoke(Native Method)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Note:
You can easily try this yourself using the following:
- Create a new Xamarin Android App
- Copy the above code into the button click (pre-made with the project)
- Create a raw folder in "Resources" and put any MP4 file inside (name it bunny or rename the video in the
SetDataAndType
) - Run the application on a device (simulator does not seem to handle this so I used my Nexus 5X)
Further more:
My device has both VLC Player and Google Photos installed, both of these can play MP4 files. And as proof if I change the data
to a URL (linking to a MP4 file) this will work fine.
This is not a matter of the file not being found as I have tested the same path using a VideoView
and it works fine.