1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.camera.gallery; 18 19 import android.content.ContentResolver; 20 import android.graphics.Bitmap; 21 import android.media.ThumbnailUtil; 22 import android.net.Uri; 23 import android.provider.MediaStore.Video; 24 import android.util.Log; 25 26 import java.io.IOException; 27 import java.io.InputStream; 28 29 /** 30 * Represents a particular video and provides access to the underlying data and 31 * two thumbnail bitmaps as well as other information such as the id, and the 32 * path to the actual video data. 33 */ 34 public class VideoObject extends BaseImage implements IImage { 35 private static final String TAG = "VideoObject"; 36 /** 37 * Constructor. 38 * 39 * @param id the image id of the image 40 * @param cr the content resolver 41 */ VideoObject(BaseImageList container, ContentResolver cr, long id, int index, Uri uri, String dataPath, long miniThumbMagic, String mimeType, long dateTaken, String title, String displayName)42 protected VideoObject(BaseImageList container, ContentResolver cr, 43 long id, int index, Uri uri, String dataPath, long miniThumbMagic, 44 String mimeType, long dateTaken, String title, String displayName) { 45 super(container, cr, id, index, uri, dataPath, miniThumbMagic, 46 mimeType, dateTaken, title, displayName); 47 } 48 49 @Override equals(Object other)50 public boolean equals(Object other) { 51 if (other == null || !(other instanceof VideoObject)) return false; 52 return fullSizeImageUri().equals( 53 ((VideoObject) other).fullSizeImageUri()); 54 } 55 56 @Override hashCode()57 public int hashCode() { 58 return fullSizeImageUri().toString().hashCode(); 59 } 60 61 @Override fullSizeBitmap(int minSideLength, int maxNumberOfPixels, boolean rotateAsNeeded, boolean useNative)62 public Bitmap fullSizeBitmap(int minSideLength, int maxNumberOfPixels, 63 boolean rotateAsNeeded, boolean useNative) { 64 return ThumbnailUtil.createVideoThumbnail(mDataPath); 65 } 66 67 @Override fullSizeImageData()68 public InputStream fullSizeImageData() { 69 try { 70 InputStream input = mContentResolver.openInputStream( 71 fullSizeImageUri()); 72 return input; 73 } catch (IOException ex) { 74 return null; 75 } 76 } 77 78 @Override fullSizeImageId()79 public long fullSizeImageId() { 80 return mId; 81 } 82 83 @Override getHeight()84 public int getHeight() { 85 return 0; 86 } 87 88 @Override getWidth()89 public int getWidth() { 90 return 0; 91 } 92 isReadonly()93 public boolean isReadonly() { 94 return false; 95 } 96 isDrm()97 public boolean isDrm() { 98 return false; 99 } 100 rotateImageBy(int degrees)101 public boolean rotateImageBy(int degrees) { 102 return false; 103 } 104 thumbBitmap(boolean rotateAsNeeded)105 public Bitmap thumbBitmap(boolean rotateAsNeeded) { 106 return fullSizeBitmap(THUMBNAIL_TARGET_SIZE, THUMBNAIL_MAX_NUM_PIXELS); 107 } 108 109 @Override miniThumbBitmap()110 public Bitmap miniThumbBitmap() { 111 try { 112 long id = mId; 113 return Video.Thumbnails.getThumbnail(mContentResolver, id, 114 Video.Thumbnails.MICRO_KIND, null); 115 } catch (Throwable ex) { 116 Log.e(TAG, "miniThumbBitmap got exception", ex); 117 return null; 118 } 119 } 120 121 @Override toString()122 public String toString() { 123 return new StringBuilder("VideoObject").append(mId).toString(); 124 } 125 }