collect icon indicating copy to clipboard operation
collect copied to clipboard

Crash when taking a video with Nexus 5

Open lognaturel opened this issue 9 years ago • 17 comments

Software and hardware versions

Collect v1.4.16, Android v6.0.1, Nexus 5

Problem description

Crash when taking a video with Nexus 5.

Steps to reproduce the problem

  1. Open a form with a video widget such as Widgets from the test server
  2. Tap "Record Video"

Other information

/storage/emulated/0/DCIM/Camera/VID_20170317_022056.mp4 doesn't exist. The path should be /storage/self/primary/DCIM/Camera/VID_20170317_022056.mp4.

I MediaWidget: Inserting VIDEO returned uri = content://media/external/video/media/264
D AndroidRuntime: Shutting down VM
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: org.odk.collect.android, PID: 3373
E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4, result=-1, data=Intent { dat=file:/storage/emulated/0/DCIM/Camera/VID_20170317_022056.mp4 flg=0x1 }} to activity {org.odk.collect.android/org.odk.collect.android.activities.FormEntryActivity}: java.lang.IllegalArgumentException: Unknown URL file:/storage/emulated/0/DCIM/Camera/VID_20170317_022056.mp4
E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
E AndroidRuntime: 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
E AndroidRuntime: 	at android.app.ActivityThread.-wrap16(ActivityThread.java)
E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:102)
E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:148)
E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Unknown URL file:/storage/emulated/0/DCIM/Camera/VID_20170317_022056.mp4
E AndroidRuntime: 	at android.content.ContentResolver.delete(ContentResolver.java:1323)
E AndroidRuntime: 	at org.odk.collect.android.activities.FormEntryActivity.onActivityResult(FormEntryActivity.java:708)
E AndroidRuntime: 	at android.app.Activity.dispatchActivityResult(Activity.java:6456)
E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
E AndroidRuntime: 	... 9 more
W ActivityManager:   Force finishing activity org.odk.collect.android/.activities.FormEntryActivity

lognaturel avatar Mar 16 '17 19:03 lognaturel

@lognaturel can i work on this ?

rajatthakur avatar Mar 16 '17 19:03 rajatthakur

@rajatthakur @lognaturel i checked out but in my case video recording is working fine. And if the user deletes the video after recording that is also working fine https://drive.google.com/open?id=0Bz5kvTbBe4fVTGk3Yk9pajlDVEE

nikhilbalyan avatar Mar 16 '17 22:03 nikhilbalyan

@nikhilbalyan Yes, it seems to be device-specific. I have also successfully recorded video with other devices

@rajatthakur Go ahead. I'd recommend seeing if you can reproduce it and/or looking in the code to see if you can find a possible explanation.

lognaturel avatar Mar 16 '17 22:03 lognaturel

Note, I believe /storage/emulated/0 is supposed to be the mountpoint for an internal SD card. I don't think this phone has one. That may or may not be relevant to the issue.

lognaturel avatar Mar 16 '17 22:03 lognaturel

@lognaturel I used the same software and hardware as you did (Nexus 5 on API level 23) but I was not able to reproduce the problem.Following is what I exactly did:

  1. Clicked on the record button.
  2. Recorded the video and clicked on the check mark.
  3. Clicked on the play button, Then it asked me to choose a player, after which the video played just fine. However, I did come across a different issue when I tried to select this video that I just recorded using the choose option.Here is a trace for the same.
E/ODKView: Attempt to invoke virtual method 'int java.lang.String.lastIndexOf(java.lang.String)' on a null object reference
           java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.lastIndexOf(java.lang.String)' on a null object reference
               at org.odk.collect.android.widgets.VideoWidget.setBinaryData(VideoWidget.java:282)
               at org.odk.collect.android.views.ODKView.setBinaryData(ODKView.java:316)
               at org.odk.collect.android.activities.FormEntryActivity.saveAudioVideoAnswer(FormEntryActivity.java:798)
               at org.odk.collect.android.activities.FormEntryActivity.onActivityResult(FormEntryActivity.java:717)
               at android.app.Activity.dispatchActivityResult(Activity.java:6428)
               at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
               at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
               at android.app.ActivityThread.-wrap16(ActivityThread.java)
               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
               at android.os.Handler.dispatchMessage(Handler.java:102)
               at android.os.Looper.loop(Looper.java:148)
               at android.app.ActivityThread.main(ActivityThread.java:5417)
               at java.lang.reflect.Method.invoke(Native Method)
               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

This is being caused by line 280 in VideoWigget.java

String binaryPath = MediaUtils.getPathFromUri(this.getContext(), (Uri) binaryuri,
                Video.Media.DATA);

The getPathFromUri method is returing a null string.

rajatthakur avatar Mar 17 '17 10:03 rajatthakur

I saw code like this in the VideoWidget, so this issue could be something similar and device (with platform) specific:

            // Need to have this ugly code to account for
            // a bug in the Nexus 7 on 4.3 not returning the mediaUri in the data
            // of the intent - using the MediaStore.EXTRA_OUTPUT to get the data
            // Have it saving to an intermediate location instead of final destination
            // to allow the current location to catch issues with the intermediate file
            Log.i(t, "The build of this device is " + android.os.Build.MODEL);
            if (NEXUS7.equals(android.os.Build.MODEL) && Build.VERSION.SDK_INT == 18) {
                nexus7Uri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
                i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, nexus7Uri);
            } else {
                i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                        Video.Media.EXTERNAL_CONTENT_URI.toString());
            }

nribeka avatar Mar 17 '17 19:03 nribeka

In FormEntryActivity -> onActivityResult -> switch (requestCode) -> case VIDEO_CAPTURE -> getContentResolver().delete(mediaUri, null, null); was throwing an exception . Adding try catch block on it fixed the bug on Nexus 5 .

kunalsingh3110 avatar Mar 18 '17 05:03 kunalsingh3110

@lognaturel did the fix suggested by @beast-incarnate solve the issue?

rajatthakur avatar Mar 18 '17 18:03 rajatthakur

I'm sorry @rajatthakur @beast-incarnate I totally missed your last couple of comments! Yes, simply catching the exception does work. @beast-incarnate would you like to submit a pull request for that? I recommend that you pull from the latest master and start your branch from there since a number of things have changed. You'll want to do the logging with Timber, for example (search the code for examples). Thanks!

lognaturel avatar Apr 21 '17 22:04 lognaturel

Sure @lognaturel , I will update my branch and submit the PR .

kunalsingh3110 avatar Apr 22 '17 07:04 kunalsingh3110

This is now suppressed by #954 but the source file isn't deleted. It would probably be good to address the root cause.

lognaturel avatar Apr 26 '17 15:04 lognaturel

Also, @nribeka had a good suggestion for something to look into here.

lognaturel avatar May 02 '17 23:05 lognaturel

Unable to reproduce the issue on Collect v1.12.2

Device : Nexus 5 Android Version : 6.0.1 Form used : Widgets

Other info:

  • Recorded the video successfully
  • Saved the form instance > Edit Saved Form > Replayed the saved video

shobhitagarwal1612 avatar Feb 23 '18 13:02 shobhitagarwal1612

Thanks, @shobhitagarwal1612! There should no longer be a crash because the error is suppressed. The source file isn't being deleted, though, right?

lognaturel avatar Feb 23 '18 18:02 lognaturel

First time it stuck at loading but then I tried again and it worked

shobhitagarwal1612 avatar Feb 23 '18 19:02 shobhitagarwal1612

@lognaturel what app did you use? Logs look similar to #705 and VideoWidget uses the same code to capturing videos so maybe the cause is the same.

grzesiek2010 avatar Oct 04 '18 10:10 grzesiek2010

I don't have that device anymore so I can't say for sure but I'm almost certain it was the built-in media application.

I think you are likely right that using the ContentResolver would solve these kinds of path issues, @grzesiek2010. I'm going to close this specific issue now because we don't have a good repro.

lognaturel avatar Oct 10 '18 23:10 lognaturel