MediaStore.ACTION_VIDEO_CAPTURE crashes camera app

2019-08-07 07:47发布

问题:

I'm using a standard MediaStore.ACTION_VIDEO_CAPTURE Intent call (e.g. the one on the Developer site or lots of StackOverflow threads) to record some video. I'm testing it on a (real) Nexus 7 (API 21) and it works fine...so long as the device's display is in a landscape orientation when the (native) Android camera app starts up. If it is portrait, reverse-portrait or reverse-landscape, the camera app stops part way through its initialization ("Unfortunately, Camera has stopped") and control returns to my app. The camera app is happy to reorient to portrait once it has initialized in landscape, however. And if I use MediaStore.ACTION_IMAGE_CAPTURE, it'll start in portrait or landscape.

I know that I can fix the orientation of my app to landscape and I know that I can request the camera to record in landscape, but if the user happens to be holding the device in portrait anyway, the screen rotates to vertical during the transition, as my app releases control to the camera app. The camera app then receives control while the orientation is portrait and it doesn't like it and stops. The issue is not due to a change of orientation -- even if I keep everything locked to portrait throughout, the camera app cancels part-way through its initialization routine.

Is there a way to avoid this happening (while still using the camera via Intent)?

(PS I notice from here, about bespoke camera routines: "Note: A camera preview does not have to be in landscape mode..." and goes on to explain how to make that happen. Does that mean that the "Intent" implementation does?)

回答1:

Is there a way to avoid this happening (while still using the camera via Intent)?

No.

More specifically, there are thousands of possible camera apps -- preloaded or installed by users -- that could claim to support ACTION_VIDEO_CAPTURE, and any of them can have bugs as this one does. There is no EXTRA_PLEASE_AVOID_BUGS that you can pass on the Intent to change that (though that'd be really cool...).