Sam Judd | de3e9ab | 2014-03-17 13:07:22 -0700 | [diff] [blame] | 1 | package com.android.camera.data; |
| 2 | |
| 3 | import android.media.MediaMetadataRetriever; |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 4 | |
| 5 | import com.android.camera.debug.Log; |
Sam Judd | de3e9ab | 2014-03-17 13:07:22 -0700 | [diff] [blame] | 6 | |
| 7 | public class VideoRotationMetadataLoader { |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame^] | 8 | private static final Log.Tag TAG = new Log.Tag("VidRotDataLoader"); |
Sam Judd | de3e9ab | 2014-03-17 13:07:22 -0700 | [diff] [blame] | 9 | private static final String ROTATION_KEY = "metadata_video_rotation"; |
| 10 | private static final String WIDTH_KEY = "metadata_video_width"; |
| 11 | private static final String HEIGHT_KEY = "metadata_video_height"; |
| 12 | |
| 13 | private static final String ROTATE_90 = "90"; |
| 14 | private static final String ROTATE_270 = "270"; |
| 15 | |
| 16 | static boolean isRotated(LocalData localData) { |
| 17 | final String rotation = localData.getMetadata().getString(ROTATION_KEY); |
| 18 | return ROTATE_90.equals(rotation) || ROTATE_270.equals(rotation); |
| 19 | } |
| 20 | |
| 21 | static int getWidth(LocalData localData) { |
| 22 | return localData.getMetadata().getInt(WIDTH_KEY); |
| 23 | |
| 24 | } |
| 25 | |
| 26 | static int getHeight(LocalData localData) { |
| 27 | return localData.getMetadata().getInt(HEIGHT_KEY); |
| 28 | } |
| 29 | |
| 30 | static void loadRotationMetdata(final LocalData data) { |
| 31 | final String path = data.getPath(); |
| 32 | MediaMetadataRetriever retriever = new MediaMetadataRetriever(); |
| 33 | try { |
| 34 | retriever.setDataSource(path); |
| 35 | String rotation = retriever.extractMetadata( |
| 36 | MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); |
| 37 | data.getMetadata().putString(ROTATION_KEY, rotation); |
| 38 | |
| 39 | String val = retriever.extractMetadata( |
| 40 | MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); |
| 41 | int width = Integer.parseInt(val); |
| 42 | |
| 43 | data.getMetadata().putInt(WIDTH_KEY, width); |
| 44 | |
| 45 | val = retriever.extractMetadata( |
| 46 | MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); |
| 47 | int height = Integer.parseInt(val); |
| 48 | |
| 49 | data.getMetadata().putInt(HEIGHT_KEY, height); |
| 50 | } catch (RuntimeException ex) { |
| 51 | // setDataSource() can cause RuntimeException beyond |
| 52 | // IllegalArgumentException. e.g: data contain *.avi file. |
| 53 | Log.e(TAG, "MediaMetdataRetriever.setDataSource() fail", ex); |
| 54 | } |
| 55 | } |
| 56 | } |