Crash when taking a video with Nexus 5
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
- Open a form with a video widget such as Widgets from the test server
- 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 can i work on this ?
@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 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.
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 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:
- Clicked on the record button.
- Recorded the video and clicked on the check mark.
- 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.
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());
}
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 .
@lognaturel did the fix suggested by @beast-incarnate solve the issue?
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!
Sure @lognaturel , I will update my branch and submit the PR .
This is now suppressed by #954 but the source file isn't deleted. It would probably be good to address the root cause.
Also, @nribeka had a good suggestion for something to look into here.
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
Thanks, @shobhitagarwal1612! There should no longer be a crash because the error is suppressed. The source file isn't being deleted, though, right?
First time it stuck at loading but then I tried again and it worked
@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.
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.