3

我使用下面的代碼來獲取JPGAVI文件的縮略圖,但我無法從.mov文件中獲取縮略圖。如何從Android中的.mov文件獲取縮略圖?

String[] projection_image = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, }; 
      String[] projection_video = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, }; 

      File file = new File(viewTag.mFileNode.mName) ; 
      String tempfilePath = file.getPath(); 

      String whereClause_image = MediaStore.Images.Media.DATA + " = '" + tempfilePath + "'"; 
      String whereClause_video = MediaStore.Video.Media.DATA + " = '" + tempfilePath + "'"; 

      ContentResolver cr = getActivity().getContentResolver(); 
      Cursor image_cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection_image, whereClause_image, null, null); 
      Cursor video_cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection_video, whereClause_video, null, null); 

      try { 

       if(image_cursor.moveToFirst()){ 
        long thumID = image_cursor.getLong(image_cursor.getColumnIndex("_ID")); 
        Bitmap bitmap_image = MediaStore.Images.Thumbnails.getThumbnail(getActivity().getContentResolver(), thumID, Images.Thumbnails.MICRO_KIND, null); 

        viewTag.mThumbnail.setImageBitmap(bitmap_image) ; 

       } 

       if(video_cursor.moveToFirst()){ 
        long thumID = video_cursor.getLong(video_cursor.getColumnIndex("_ID")); 
        Bitmap bitmap_video = MediaStore.Video.Thumbnails.getThumbnail(getActivity().getContentResolver(), thumID, Video.Thumbnails.MICRO_KIND, null); 
        viewTag.mThumbnail.setImageBitmap(bitmap_video) ;    
       } 

      } catch (NullPointerException e) { 
       // TODO: handle exception 
       Log.i(TAG, "cursor---NullPointerException"); 

       image_cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection_image, whereClause_image, null, null); 
       video_cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection_video, whereClause_video, null, null); 

      } finally{ 
       image_cursor.close(); 
       video_cursor.close(); 
      } 

是否有人知道如何在Android中使用MediaStore擺脫傳送文件的縮略圖?

+0

我認爲不支持在Android .mov文件,請對支持的媒體類型看看這裏[支持的媒體格式(http://developer.android.com/guide/appendix/media-formats.html ) – 2014-02-11 06:02:49

回答

1
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path, 
    MediaStore.Images.Thumbnails.MINI_KIND); 
相關問題