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