@Override protected Bitmap doInBackground(Void... params) { Bitmap bitmap = null; try { bitmap = ThumbnailUtils.createVideoThumbnail(mImageKey, Thumbnails.FULL_SCREEN_KIND); if (bitmap != null) { bitmap = Bitmap.createScaledBitmap(bitmap, mMaxWidth, mMaxWidth, false); addBitmapToCache(mImageKey, bitmap); return bitmap; } return null; } catch (Exception e) { if (e != null) { e.printStackTrace(); } return null; } }
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException { ContentResolver res = this.context.getContentResolver(); Uri uri = Uri.parse(imageUri); if (isVideoContentUri(uri)) { Bitmap bitmap = Thumbnails.getThumbnail(res, Long.valueOf(uri.getLastPathSegment()) .longValue(), 1, null); if (bitmap != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0, bos); return new ByteArrayInputStream(bos.toByteArray()); } } else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { return getContactPhotoStream(uri); } return res.openInputStream(uri); }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder=new ViewHolder(); convertView = mInflater.inflate(R.layout.videos_list_item, null); holder.thumb = (ImageView)convertView.findViewById(R.id.video_thumb); holder.name = (TextView)convertView.findViewById(R.id.video_name); holder.time = (TextView)convertView.findViewById(R.id.video_file_created_time); holder.duration = (TextView) convertView.findViewById(R.id.video_total_duration); convertView.setTag(holder); }else { logd("convertView != null, reuse"); holder = (ViewHolder)convertView.getTag(); } VideosInfo videoInfo = new VideosInfo(mVideosPaths.get(position)); //holder.thumb.setImageBitmap(ExtractPicturesWorker.extractBitmap(mVideosPaths.get(position), 0)); holder.thumb.setImageBitmap(ThumbnailUtils.createVideoThumbnail(mVideosPaths.get(position), Thumbnails.MINI_KIND)); holder.name.setText("文件名:" + videoInfo.getName()); holder.time.setText("时间:" + videoInfo.getLastModifyTime()); holder.duration.setText("时长:" + videoInfo.getDuration()); return convertView; }
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException { ContentResolver res = this.context.getContentResolver(); Uri uri = Uri.parse(imageUri); if (isVideoUri(uri)) { Bitmap bitmap = Thumbnails.getThumbnail(res, Long.valueOf(uri.getLastPathSegment()).longValue(), 1, null); if (bitmap != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 0, bos); return new ByteArrayInputStream(bos.toByteArray()); } } else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { return Contacts.openContactPhotoInputStream(res, uri); } return res.openInputStream(uri); }
public Bitmap getVideoThumbnail() { final Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(mVideoFile.getFullPath(), Thumbnails.FULL_SCREEN_KIND); if (thumbnail == null) { CLog.d(CLog.ACTIVITY, "Failed to generate video preview"); } return thumbnail; }
/** * 获取视频图像 * * @param videoPath * @return */ public static Bitmap getVideoThumbnail(String videoPath) { Bitmap bitmap = null; bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, Thumbnails.MINI_KIND); bitmap = ThumbnailUtils.extractThumbnail(bitmap, 100, 100, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; }
private String createPreviewImage() throws IOException { previewImage = null; Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.FULL_SCREEN_KIND); if (bitmap != null) { previewImage = foldername + File.separator + Calendar.getInstance().getTimeInMillis() + ".jpg"; File file = new File(previewImage); FileOutputStream stream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); stream.flush(); } return previewImage; }
private String createThumbnailOfVideo() throws IOException { String thumbnailPath = null; Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND); if (bitmap != null) { thumbnailPath = foldername + File.separator + Calendar.getInstance().getTimeInMillis() + ".jpg"; File file = new File(thumbnailPath); FileOutputStream stream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); stream.flush(); } return thumbnailPath; }
@Override protected Drawable doInBackground(Void... params) { Drawable drawable = null; Bitmap bitmap = null; ContentResolver contentResolver = imageView.getContext().getContentResolver(); if (media.isVideo()) { bitmap = MediaStore.Video.Thumbnails.getThumbnail(contentResolver, media.getId(), MediaStore.Video.Thumbnails.MINI_KIND, null); if (bitmap == null) { // can`t get thumb from media database, use // thumb if (media.isVideo()) { bitmap = ThumbnailUtils.createVideoThumbnail(media.getPath(), Thumbnails.MINI_KIND); } } } else { bitmap = ImageUtils.decodeBitmapFromFile(media.getPath(), imageView.getWidth(), imageView.getHeight()); } if (bitmap != null) { drawable = new BitmapDrawable(res, bitmap); } return drawable; }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.v("Create:::", "onCreateView called"); View rootView = inflater.inflate(R.layout.video_fragment, container, false); set=(Button) rootView.findViewById(R.id.button_set_alarm); set.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { startActivity(new Intent(getActivity(),SetAlarmActivity.class)); } }); mVideoView = (VideoView) rootView.findViewById(R.id.shouye_video_view); mVideoView.setOnTouchListener(this); mVideoView.setOnCompletionListener(this); MediaController mc = new MediaController(this.getActivity()); mc.setVisibility(View.INVISIBLE); mVideoView.setMediaController(mc); String path = "android.resource://com.qd.clock/" + R.raw.video1; Bitmap thumbAsBitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.FULL_SCREEN_KIND); Bitmap image = this.getVideoThumbnailWithId(R.raw.video1); mVideoView.setBackgroundResource(R.drawable.img_48); return rootView; }
@Override protected Bitmap processBitmap(Object data) { String filePath= String.valueOf(data); return ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND); }
@Override protected Bitmap processBitmap(Object data) { String filePath=String.valueOf(data); return ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND); }
public static Bitmap loadImageFromFilePath(String filePath) { return ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND); }
private Bitmap getThumbnail() { if (filename == null) return null; return ThumbnailUtils.createVideoThumbnail(filename, Thumbnails.FULL_SCREEN_KIND); }
@TargetApi(11) public static Bitmap a(Context paramContext, Uri paramUri, Bitmap paramBitmap) { int i1 = -1; if (paramUri == null) {} while (!c(paramUri)) { return null; } ContentResolver localContentResolver = paramContext.getContentResolver(); long l1 = ContentUris.parseId(paramUri); BitmapFactory.Options localOptions = new BitmapFactory.Options(); String str1; Bitmap localBitmap; if (Build.VERSION.SDK_INT >= 19) { if ((paramBitmap != null) && (paramBitmap.getWidth() == 512) && (paramBitmap.getHeight() == 384)) { localOptions.inBitmap = paramBitmap; } } else { str1 = mfq.b(localContentResolver, paramUri); if (!mfq.b(str1)) { break label198; } localBitmap = MediaStore.Images.Thumbnails.getThumbnail(localContentResolver, l1, 1, localOptions); } for (;;) { return localBitmap; if (!Log.isLoggable("MediaStoreUtil", 3)) { break; } boolean bool; if (paramBitmap == null) { bool = true; label122: if (paramBitmap == null) { break label192; } } label192: for (int i2 = paramBitmap.getWidth();; i2 = i1) { if (paramBitmap != null) { i1 = paramBitmap.getHeight(); } new StringBuilder(117).append("getMediaStoreThumbnail: got null or bitmap with invalid dimensions null? ").append(bool).append(" width: ").append(i2).append(" height: ").append(i1); break; bool = false; break label122; } label198: if (mfq.c(str1)) { localBitmap = MediaStore.Video.Thumbnails.getThumbnail(localContentResolver, l1, 1, localOptions); } else { if (Log.isLoggable("MediaStoreUtil", 5)) { String str2 = String.valueOf(paramUri); new StringBuilder(42 + String.valueOf(str1).length() + String.valueOf(str2).length()).append("getThumbnail: unrecognized mimeType=").append(str1).append(", uri=").append(str2); } localBitmap = null; } } }
@Override public boolean getRow(BitmapWrapper outRow, int id) { Bitmap fullThumb; if((id & VIDEO_BIT) != 0) { //first check if the media exists at all //note, even if the media doesn't exist, the thumbnail might //still exist, so we have to do this separate check to avoid //showing the user deleted media if(!Util.mediaExists(context, id - VIDEO_BIT,false)) return false; fullThumb = MediaStore.Video.Thumbnails.getThumbnail( context.getContentResolver(), id - VIDEO_BIT, MediaStore.Video.Thumbnails.MICRO_KIND, null); //if the gallery hasn't created a thumbnail yet, we relunctantly create //our own, which is only stored in memory. We aren't caching our own images //because it seems creepy to create our own thumbnails of everything if(fullThumb == null) { Log.d(GTG.TAG,"creating own thumbnail for video id "+id); fullThumb = ThumbnailUtils.createVideoThumbnail( Util.getDataFilepathForMedia(context.getContentResolver(), id - VIDEO_BIT, false), Thumbnails.MICRO_KIND); } } else if((id & IMAGE_BIT) != 0) { //first check if the media exists at all //note, even if the media doesn't exist, the thumbnail might //still exist, so we have to do this separate check to avoid //showing the user deleted images if(!Util.mediaExists(context, id- IMAGE_BIT,true)) return false; fullThumb = MediaStore.Images.Thumbnails.getThumbnail( context.getContentResolver(), id - IMAGE_BIT, MediaStore.Images.Thumbnails.MICRO_KIND, null); //if the gallery hasn't created a thumbnail yet, we relunctantly create //our own, which is only stored in memory. We aren't caching our own images //because it seems creepy to create our own thumbnails of everything if(fullThumb == null) { Log.d(GTG.TAG,"creating own thumbnail for image id "+id); fullThumb = ThumbnailUtils.extractThumbnail(Util.getBitmap(context, id - IMAGE_BIT, true), width, height); } } else throw new IllegalStateException(); if(fullThumb == null) { //sometimes the extractThumbnail returns null, in which case, we just return false, indicating to delete //the media item return false; } outRow.bitmap = Bitmap.createScaledBitmap(fullThumb, width, height, false); outRow.id = id; return true; }
@Override protected Bitmap processBitmap(Object data) { String filePath = String.valueOf(data); return ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND); }
private Runnable getThumbnailRunnable(final MediaVO media, final ImageView imageView) { final Runnable loadImage = new Runnable() { public void run() { Bitmap bitmap = null; final Context context = imageView.getContext(); // get thumb from media database if (media.isVideo()) { bitmap = MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(), media.getId(), MediaStore.Video.Thumbnails.MICRO_KIND, null); } else { bitmap = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), media.getId(), MediaStore.Images.Thumbnails.MICRO_KIND, null); } if (bitmap == null) { if (media.isVideo()) { bitmap = ThumbnailUtils.createVideoThumbnail(media.getPath(), Thumbnails.MICRO_KIND); } else { bitmap = ImageUtils.decodeBitmapFromFile(media.getPath(), imageView.getWidth(), imageView.getHeight()); } } if (bitmap != null) { handler.post(new OnThumbnailReadyMessage(imageView, media.getKey(), new BitmapDrawable(context.getResources(), bitmap))); } else { Log.w("ThumbnailWorker", "Can't load thumbnail for file " + media.getPath()); } } }; return loadImage; }
private Bitmap getVideoThumbnailWithId(int rsid) { Bitmap imageBitmap = CommonHelp.getVideoThumbnail( CommonHelp.pathFromRawResourceId(rsid), 300, 300, Thumbnails.FULL_SCREEN_KIND); return imageBitmap; }