2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.camera.data;
19 import android.media.MediaMetadataRetriever;
21 import com.android.camera.debug.Log;
23 public class VideoRotationMetadataLoader {
24 private static final Log.Tag TAG = new Log.Tag("VidRotDataLoader");
26 private static final String ROTATE_90 = "90";
27 private static final String ROTATE_270 = "270";
29 static boolean isRotated(FilmstripItem filmstripItem) {
30 final String rotation = filmstripItem.getMetadata().getVideoOrientation();
31 return ROTATE_90.equals(rotation) || ROTATE_270.equals(rotation);
34 static boolean loadRotationMetadata(final FilmstripItem data) {
35 final String path = data.getData().getFilePath();
36 MediaMetadataRetriever retriever = new MediaMetadataRetriever();
38 retriever.setDataSource(path);
39 data.getMetadata().setVideoOrientation(retriever.extractMetadata(
40 MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
42 String val = retriever.extractMetadata(
43 MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
45 data.getMetadata().setVideoWidth(Integer.parseInt(val));
47 val = retriever.extractMetadata(
48 MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
50 data.getMetadata().setVideoHeight(Integer.parseInt(val));
51 } catch (RuntimeException ex) {
52 // setDataSource() can cause RuntimeException beyond
53 // IllegalArgumentException. e.g: data contain *.avi file.
54 Log.e(TAG, "MediaMetdataRetriever.setDataSource() fail", ex);