Java – Android Intent with EXTRA_OUTPUT MediaStore.ACTION_VIDEO_CAPTURE crashes while playing, remakes

Android Intent with EXTRA_OUTPUT MediaStore.ACTION_VIDEO_CAPTURE crashes while playing, remakes… here is a solution to the problem.

Android Intent with EXTRA_OUTPUT MediaStore.ACTION_VIDEO_CAPTURE crashes while playing, remakes

I’m trying to make an app that records a video and saves it to an SD card, and when it runs again it overwrites the previous video.

The problem is that when I specify an extra intent EXTRA_OUTPUT, the camera records video to that location, but crashes when retaking and playing clicks.

The code I used is as follows:

_path = Environment.getExternalStorageDirectory() + "/examplevideo.3gp";

File file = new File(_path);
Uri outputFileUri = Uri.fromFile(file);

Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE );
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);            
startActivityForResult(intent, 0);

When I stop recording, logcat is displayed

VERBOSE/videocamera(6602): Setting current video filename: null

It’s weird and seems to be a problem.

When I press play,

I get an error, but the app keeps running (the recorded video does not play).

ERROR/videocamera(6602): Couldn't view video file:///mnt/sdcard/examplevideo.3gp
ERROR/videocamera(6602): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/examplevideo.3gp }
ERROR/videocamera(6602):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
ERROR/videocamera(6602):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
ERROR/videocamera(6602):     at android.app.Activity.startActivityForResult(Activity.java:2817)
ERROR/videocamera(6602):     at android.app.Activity.startActivity(Activity.java:2923)
..

When I press retake, the app crashes completely with an error :

ERROR/AndroidRuntime(6602): FATAL EXCEPTION: main
ERROR/AndroidRuntime(6602): java.lang.IllegalArgumentException: Unknown URL file:///mnt/sdcard/examplevideo.3gp
ERROR/AndroidRuntime(6602):     at android.content.ContentResolver.delete(ContentResolver.java:671)
ERROR/AndroidRuntime(6602):     at com.android.camera.VideoCamera.deleteCurrentVideo(VideoCamera.java:1010)
ERROR/AndroidRuntime(6602):     at com.android.camera.VideoCamera.discardCurrentVideoAndInitRecorder(VideoCamera.java:476)
ERROR/AndroidRuntime(6602):     at com.android.camera.VideoCamera.onClick(VideoCamera.java:420)
ERROR/AndroidRuntime(6602):     at android.view.View.performClick(View.java:2408)
...

Oddly enough, this video is saved to a given location and I can play it from my sdcard, it’s just that the camera activity doesn’t recognize it.

Some help or ideas would be appreciated!

Solution

It looks like you’re trying to launch the video player based on the error message instead of playing the video in the VideoView widget.

Try specifying your intent data as the video type:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(yourVideoURI), "video/*");
startActivity(i);

Note that the yourVideoURI above will be what you returned from data.getData() in onActivityResult().

Related Problems and Solutions