Sunday 15 April 2012

Android, Which Camera Was Used With MediaStore.ACTION_VIDEO_CAPTURE ? (Front or Back) -



Android, Which Camera Was Used With MediaStore.ACTION_VIDEO_CAPTURE ? (Front or Back) -

simple working code:

m_takevideointent = new intent(mediastore.action_video_capture); if (m_takevideointent.resolveactivity(mainactivity.this.getpackagemanager()) != null) { startactivityforresult(m_takevideointent, request_video_capture); } // , when done: @override public void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode == result_ok) { if (requestcode == request_video_capture) { // code } else { // other code } } }

question:

how can know in onactivityresult(..) photographic camera used, front end or ?

or

how can forcefulness new intent(mediastore.action_video_capture) utilize front end or photographic camera ?

(this because when using front end photographic camera - result video plays upside down.)

this bit long has useful info going wrong when video plays in wrong orientation. nice drink , read on...

original questions

how can forcefulness new intent(mediastore.action_video_capture) utilize front end or camera?

as stated elsewhere, there (unreliable) method inquire photographic camera or video activity open in either front end photographic camera or rear photographic camera mode.

besides unreliability of method, there nil prevent user switching front/rear mode after photographic camera opens, never solution problem of upside-down video playback.

how can know in onactivityresult(..) photographic camera used, front end or back?

there no way know of. but...

front vs. photographic camera not problem anyways.

the underlying problem that, with media players, video captured android device may play in wrong orientation. because, according mediarecorder docs, setting orientation hint

... not trigger source video frame rotate during video recording, add together composition matrix containing rotation angle in output video...

and unfortunately:

some video players may take ignore compostion matrix in video during playback.

reading video orientation

although media players ignore orientation hint, own code can read it.

public void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode == result_ok && requestcode == request_video_capture) { uri vid = data.getdata(); log.i("xcode", "video captured: " + data.getdata()); mediametadataretriever mmr = new mediametadataretriever(); mmr.setdatasource(this, vid); string foo = mmr .extractmetadata(mediametadataretriever.metadata_key_video_rotation); log.i("xcode", "video captured: " + data.getdata() + " rotation: " + foo); } }

(note in order read metadata returned video, need provide mediastore.extra_output field when request it, recommended camera docs.)

when run code, next results:

rear camera, portrait, rotation == 90 front camera, portrait, rotation == 270 rear camera, landscape, rotation == 180 front camera, landscape, rotation == 180

it looks these video captures can problematic players when rotation 270, videos should select out fixed post-processing.

android android-intent video camera back

No comments:

Post a Comment