Code example for MediaMetadataRetriever

Methods: extractMetadata, release, setDataSource

0
		    } while (cursor.moveToNext());
		} 
	} 
	 
	public static void getMediaInfo(String path, MediaBean bean){
		MediaMetadataRetriever retriever = new MediaMetadataRetriever();
		retriever.setDataSource(path);
		 
		File file=new File(path);
		if(file!=null){
			Log.i("TAG", "地址可用!");
			long length=file.length();
			bean.setSize(length/(1024*1024));
		} 
		 
		if(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)!=null){
			bean.setTitle(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));
		}else{ 
			String title = path.substring(path.lastIndexOf(File.separator)+1);
			bean.setTitle(title);
		} 
		 
		if(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)!=null){
			bean.setWidth(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
		}else{ 
			bean.setWidth("*");
		} 
		 
		if(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)!=null){
			bean.setHeight(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
		}else{ 
			bean.setHeight("*");
		} 
		 
		if(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)!=null){
			bean.setDuration(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
		}else{ 
			bean.setDuration("*");
		} 
		 
		Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(path, 0);
		bean.setBitmap(bitmap);
		/*byte[] buffer = retriever.getEmbeddedPicture(); 
		if(buffer!=null){ 
			bean.setBitmap(BitmapFactory.decodeByteArray(buffer, 0, buffer.length)); 
		}else{ 
			bean.setBitmap(retriever.getFrameAtTime(Long.parseLong(bean.getDuration())/2)); 
		}*/ 
		 
		retriever.release();
	} 
	 
	public static StringBuilder turnNumToTime(int progress){
		StringBuilder str = new StringBuilder();
		int second=progress/1000;