App crashes when picking video from gallery

I am having trouble trying to select videos on Android. I am using the code below to launch the activity.

var intent = new Intent();
            intent.SetType("video/*");
            intent.SetAction(Intent.ActionGetContent);
            this.StartActivityForResult(Intent.CreateChooser(intent, "Select video"), 200);

Then in the OnActivityResult callback I use the following code to get the URI of the data.

 public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (requestCode == 200 && resultCode == Result.Ok)
        {
            try
            {
                Android.Net.Uri contentURI = data.Data;

                ICursor cursor = Activity.ContentResolver.Query(contentURI, null, null, null, null);
                cursor.MoveToFirst();
                string documentId = cursor.GetString(0);
                documentId = documentId.Split(':')[1];
                cursor.Close();

                cursor = Activity.ContentResolver.Query(
                Android.Provider.MediaStore.Video.Media.ExternalContentUri,
                null, MediaStore.Video.Media.InterfaceConsts.Id + " = ? ", new[] { documentId }, null);
                cursor.MoveToFirst();
                string selectedPath = cursor.GetString(cursor.GetColumnIndex(MediaStore.Video.Media.InterfaceConsts.Data));

                var fileBytes = System.IO.File.ReadAllBytes(selectedPath);

                //await UploadFile(fileBytes);

            }
            catch (Java.Lang.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
    }

The app crashes soon after the gallery is opened. I'm using Sony Xperia ion with Android version 4.0.3 to debug the app. The first time I tested my code, it functioned but now every time the gallery opens up, the app crashes. It doesn't crash when I'm uploading an image file.

Here's my full logcat:

    4-28 02:15:18.102 D/Mono    (10277): DllImport attempting to load: '__Internal'.
04-28 02:15:18.102 D/Mono    (10277): DllImport loaded library '(null)'.
04-28 02:15:18.102 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.102 D/Mono    (10277): Searching for '_monodroid_lref_log_new'.
04-28 02:15:18.102 D/Mono    (10277): Probing '_monodroid_lref_log_new'.
04-28 02:15:18.102 D/Mono    (10277): Found as '_monodroid_lref_log_new'.
04-28 02:15:18.112 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.112 D/Mono    (10277): Searching for '_monodroid_lref_log_delete'.
04-28 02:15:18.112 D/Mono    (10277): Probing '_monodroid_lref_log_delete'.
04-28 02:15:18.112 D/Mono    (10277): Found as '_monodroid_lref_log_delete'.
04-28 02:15:18.112 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.112 D/Mono    (10277): Searching for '_monodroid_gref_log_new'.
04-28 02:15:18.112 D/Mono    (10277): Probing '_monodroid_gref_log_new'.
04-28 02:15:18.112 D/Mono    (10277): Found as '_monodroid_gref_log_new'.
04-28 02:15:18.142 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.142 D/Mono    (10277): Searching for '_monodroid_get_identity_hash_code'.
04-28 02:15:18.142 D/Mono    (10277): Probing '_monodroid_get_identity_hash_code'.
04-28 02:15:18.142 D/Mono    (10277): Found as '_monodroid_get_identity_hash_code'.
04-28 02:15:18.263 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.263 D/Mono    (10277): Searching for 'monodroid_typemap_java_to_managed'.
04-28 02:15:18.263 D/Mono    (10277): Probing 'monodroid_typemap_java_to_managed'.
04-28 02:15:18.263 D/Mono    (10277): Found as 'monodroid_typemap_java_to_managed'.
04-28 02:15:18.413 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.413 D/Mono    (10277): Searching for '_monodroid_gref_log'.
04-28 02:15:18.413 D/Mono    (10277): Probing '_monodroid_gref_log'.
04-28 02:15:18.413 D/Mono    (10277): Found as '_monodroid_gref_log'.
04-28 02:15:18.453 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:18.453 D/Mono    (10277): Searching for 'monodroid_typemap_managed_to_java'.
04-28 02:15:18.453 D/Mono    (10277): Probing 'monodroid_typemap_managed_to_java'.
04-28 02:15:18.453 D/Mono    (10277): Found as 'monodroid_typemap_managed_to_java'.
04-28 02:15:18.503 D/Mono    (10277): Image addref System.Core[0xe692e8] -> System.Core.dll[0xe77a50]: 1
04-28 02:15:18.503 D/Mono    (10277): Assembly System.Core[0xe692e8] added to domain RootDomain, ref_count=1
04-28 02:15:18.503 D/Mono    (10277): AOT module 'System.Core.dll.so' not found: Cannot load library: load_library[1091]: Library '/data/data/com.dualdub.androclient/lib/libaot-System.Core.dll.so' not found
04-28 02:15:18.503 D/Mono    (10277): AOT module '/Users/builder/data/lanes/3053/a94a03b5/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Core.dll.so' not found: Cannot load library: load_library[1091]: Library '/data/data/com.dualdub.androclient/lib/libaot-System.Core.dll.so' not found
04-28 02:15:18.523 D/Mono    (10277): Unloading image data-0x63529008 [0xe86468].
04-28 02:15:18.523 D/Mono    (10277): Assembly Ref addref Mono.Android[0xca8958] -> System.Core[0xe692e8]: 2
04-28 02:15:18.533 D/Mono    (10277): Assembly Ref addref System.Core[0xe692e8] -> mscorlib[0xc76d38]: 3
Loaded assembly: System.Core.dll
04-28 02:15:19.123 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:19.123 D/Mono    (10277): Searching for '_monodroid_gref_log_delete'.
04-28 02:15:19.123 D/Mono    (10277): Probing '_monodroid_gref_log_delete'.
04-28 02:15:19.123 D/Mono    (10277): Found as '_monodroid_gref_log_delete'.
04-28 02:15:19.143 D/Mono    (10277): DllImport searching in: '__Internal' ('(null)').
04-28 02:15:19.143 D/Mono    (10277): Searching for '_monodroid_gc_wait_for_bridge_processing'.
04-28 02:15:19.143 D/Mono    (10277): Probing '_monodroid_gc_wait_for_bridge_processing'.
04-28 02:15:19.143 D/Mono    (10277): Found as '_monodroid_gc_wait_for_bridge_processing'.
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref OkHttp[0xc5e660] -> mscorlib[0xc76d38]: 4
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref OkHttp[0xc5e660] -> Mono.Android[0xca8958]: 2
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Refractored.Controls.CircleImageView[0xbe5e30] -> mscorlib[0xc76d38]: 5
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Refractored.Controls.CircleImageView[0xbe5e30] -> Mono.Android[0xca8958]: 3
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.Animated.Vector.Drawable[0xc392e0] -> mscorlib[0xc76d38]: 6
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.Animated.Vector.Drawable[0xc392e0] -> Mono.Android[0xca8958]: 4
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.Design[0xc38300] -> mscorlib[0xc76d38]: 7
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.Design[0xc38300] -> Mono.Android[0xca8958]: 5
04-28 02:15:19.173 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v4[0xbe7ef8] -> mscorlib[0xc76d38]: 8
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v4[0xbe7ef8] -> Mono.Android[0xca8958]: 6
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v7.AppCompat[0xb7ff80] -> mscorlib[0xc76d38]: 9
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v7.AppCompat[0xb7ff80] -> Mono.Android[0xca8958]: 7
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v7.CardView[0xbdea28] -> mscorlib[0xc76d38]: 10
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v7.CardView[0xbdea28] -> Mono.Android[0xca8958]: 8
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v7.RecyclerView[0xc2b0d0] -> mscorlib[0xc76d38]: 11
04-28 02:15:19.183 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.v7.RecyclerView[0xc2b0d0] -> Mono.Android[0xca8958]: 9
04-28 02:15:19.193 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.Vector.Drawable[0xc22340] -> mscorlib[0xc76d38]: 12
04-28 02:15:19.193 D/Mono    (10277): Assembly Ref addref Xamarin.Android.Support.Vector.Drawable[0xc22340] -> Mono.Android[0xca8958]: 10
04-28 02:15:19.193 D/Mono    (10277): Assembly Ref addref Yourtime[0xc28778] -> Mono.Android[0xca8958]: 11
Loaded assembly: MonoDroidConstructors [External]
04-28 02:15:19.444 D/Mono    (10277): Assembly Ref addref Yourtime[0xc28778] -> mscorlib[0xc76d38]: 13
04-28 02:15:20.234 D/Mono    (10277): Image addref System.Net.Http[0x1255c38] -> System.Net.Http.dll[0x1256b70]: 1
04-28 02:15:20.234 D/Mono    (10277): Assembly System.Net.Http[0x1255c38] added to domain RootDomain, ref_count=1
04-28 02:15:20.234 D/Mono    (10277): AOT module 'System.Net.Http.dll.so' not found: Cannot load library: load_library[1091]: Library '/data/data/com.dualdub.androclient/lib/libaot-System.Net.Http.dll.so' not found
04-28 02:15:20.234 D/Mono    (10277): AOT module '/Users/builder/data/lanes/3053/a94a03b5/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Net.Http.dll.so' not found: Cannot load library: load_library[1091]: Library '/data/data/com.dualdub.androclient/lib/libaot-System.Net.Http.dll.so' not found
04-28 02:15:20.234 D/Mono    (10277): Unloading image data-0x125e3e8 [0x1256fc0].
04-28 02:15:20.234 D/Mono    (10277): Assembly Ref addref Yourtime[0xc28778] -> System.Net.Http[0x1255c38]: 2
04-28 02:15:20.244 D/Mono    (10277): Assembly Ref addref System.Net.Http[0x1255c38] -> mscorlib[0xc76d38]: 14
Resolved pending breakpoint at 'CameraFragment.cs:320,1' to void Yourtime.Fragments.CameraFragment.OnActivityResult (int requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00000].
Loaded assembly: System.Net.Http.dll
04-28 02:15:20.505 D/Mono    (10277): Image addref System.Xml[0x12c3d68] -> System.Xml.dll[0x12c9890]: 1
04-28 02:15:20.505 D/Mono    (10277): Assembly System.Xml[0x12c3d68] added to domain RootDomain, ref_count=1
04-28 02:15:20.505 D/Mono    (10277): AOT module 'System.Xml.dll.so' not found: Cannot load library: load_library[1091]: Library '/data/data/com.dualdub.androclient/lib/libaot-System.Xml.dll.so' not found
04-28 02:15:20.505 D/Mono    (10277): AOT module '/Users/builder/data/lanes/3053/a94a03b5/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Xml.dll.so' not found: Cannot load library: load_library[1091]: Library '/data/data/com.dualdub.androclient/lib/libaot-System.Xml.dll.so' not found
04-28 02:15:20.535 D/Mono    (10277): Unloading image data-0x63800008 [0x12c4080].
04-28 02:15:20.535 D/Mono    (10277): Assembly Ref addref Mono.Android[0xca8958] -> System.Xml[0x12c3d68]: 2
04-28 02:15:20.545 D/Mono    (10277): Assembly Ref addref System.Xml[0x12c3d68] -> mscorlib[0xc76d38]: 15
Loaded assembly: System.Xml.dll
04-28 02:15:21.285 I/dalvikvm(10277): Could not find method android.view.SurfaceView.<init>, referenced from method md5b48e0788c01ac4725f8b67ece4dbb3b8.CameraS.<init>
04-28 02:15:21.285 W/dalvikvm(10277): VFY: unable to resolve direct method 18819: Landroid/view/SurfaceView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;II)V
04-28 02:15:21.285 D/dalvikvm(10277): VFY: replacing opcode 0x70 at 0x0000
04-28 02:15:21.386 D/libEGL  (10277): loaded /system/lib/egl/libGLES_android.so
04-28 02:15:21.386 D/libEGL  (10277): loaded /system/lib/egl/libEGL_adreno200.so
04-28 02:15:21.396 D/libEGL  (10277): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
04-28 02:15:21.396 D/libEGL  (10277): loaded /system/lib/egl/libGLESv2_adreno200.so
04-28 02:15:21.456 I/Adreno200-EGLSUB(10277): <ConfigWindowMatch:2078>: Format RGBA_8888.
04-28 02:15:21.466 D/memalloc(10277): /dev/pmem: Mapped buffer base:0x63d17000 size:3768320 offset:0 fd:70
04-28 02:15:21.476 E/        (10277): Can't open file for reading
04-28 02:15:21.476 E/        (10277): Can't open file for reading
04-28 02:15:21.476 D/OpenGLRenderer(10277): Enabling debug mode 0
04-28 02:15:21.696 D/memalloc(10277): /dev/pmem: Mapped buffer base:0x6430d000 size:7536640 offset:3768320 fd:73
04-28 02:15:21.736 D/memalloc(10277): /dev/pmem: Mapped buffer base:0x64a3d000 size:29986816 offset:26218496 fd:76
04-28 02:15:25.840 D/TextLayoutCache(10277): Using debug level: 0 - Debug Enabled: 0
04-28 02:15:25.890 I/Adreno200-EGLSUB(10277): <ConfigWindowMatch:2078>: Format RGBA_8888.
04-28 02:15:25.890 D/memalloc(10277): /dev/pmem: Mapped buffer base:0x67032000 size:9981952 offset:7999488 fd:83
04-28 02:15:25.960 D/memalloc(10277): /dev/pmem: Mapped buffer base:0x67b42000 size:43724800 offset:41742336 fd:89
04-28 02:15:27.061 D/memalloc(10277): /dev/pmem: Mapped buffer base:0x6a4f5000 size:24375296 offset:22392832 fd:92
04-28 02:15:29.023 D/OpenGLRenderer(10277): Flushing caches (mode 0)
04-28 02:15:29.023 D/memalloc(10277): /dev/pmem: Unmapping buffer base:0x63d17000 size:3768320 offset:0
04-28 02:15:29.023 D/memalloc(10277): /dev/pmem: Unmapping buffer base:0x6430d000 size:7536640 offset:3768320
04-28 02:15:29.023 D/memalloc(10277): /dev/pmem: Unmapping buffer base:0x64a3d000 size:29986816 offset:26218496
04-28 02:15:29.073 D/OpenGLRenderer(10277): Flushing caches (mode 0)
04-28 02:15:29.083 D/memalloc(10277): /dev/pmem: Unmapping buffer base:0x67032000 size:9981952 offset:7999488
04-28 02:15:29.083 D/memalloc(10277): /dev/pmem: Unmapping buffer base:0x67b42000 size:43724800 offset:41742336
04-28 02:15:29.083 D/memalloc(10277): /dev/pmem: Unmapping buffer base:0x6a4f5000 size:24375296 offset:22392832
04-28 02:15:29.554 D/OpenGLRenderer(10277): Flushing caches (mode 2

)

I have setup a breaking point at the start of OnActionResultActivity but the app crashes before the debugger get's there. Does anyone have any idea how to get video data from the video chooser?

Answers

  • MindGhost505MindGhost505 RUMember

    Hi!
    Same problem. Start choose activity from example. Firsts everal tests was ok. After... each time crashing while gallary is opened. No info in my code after crash.
    Anyone know the issue?

Sign In or Register to comment.