|
|
@@ -75,14 +75,7 @@ public class MediaUtils {
|
|
|
do {
|
|
|
MediaBean item = parseImageCursorAndCreateThumImage(context, cursor);
|
|
|
mediaBeanList.add(item);
|
|
|
- //检查并重新设置宽高
|
|
|
- if (item != null && item.getOriginalPath() != null) {
|
|
|
- if (item.getHeight() <= 0 || item.getWidth() <= 0) {
|
|
|
- BitmapFactory.Options options = getImageOptions(item.getOriginalPath());
|
|
|
- item.setWidth(options.outWidth);
|
|
|
- item.setHeight(options.outHeight);
|
|
|
- }
|
|
|
- }
|
|
|
+ checkImgMediaBean(item);
|
|
|
} while (cursor.moveToNext());
|
|
|
}
|
|
|
}
|
|
|
@@ -138,25 +131,7 @@ public class MediaUtils {
|
|
|
do {
|
|
|
MediaBean item = parseVideoCursorAndCreateThumImage(context, cursor);
|
|
|
mediaBeanList.add(item);
|
|
|
- //检查并重新设置宽高
|
|
|
- if (item != null && item.getOriginalPath() != null) {
|
|
|
- if (item.getHeight() <= 0 || item.getWidth() <= 0 || item.getOrientation() == -1) {
|
|
|
- try {
|
|
|
- MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
|
|
|
- metadataRetriever.setDataSource(context, Uri.parse(item.getOriginalPath()));
|
|
|
- String width = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); // 视频宽度
|
|
|
- String height = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); // 视频高度
|
|
|
- String rotation = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); // 视频旋转方向
|
|
|
-
|
|
|
- item.setWidth(Float.valueOf(width).intValue());
|
|
|
- item.setHeight(Float.valueOf(height).intValue());
|
|
|
- item.setOrientation(Float.valueOf(rotation).intValue());
|
|
|
- LogUtil.println("getMediaWithVideoList", width, height, rotation);
|
|
|
- } catch (Exception e){
|
|
|
- LogUtil.println("getMediaWithVideoList", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ checkVideoMediaBean(context, item);
|
|
|
} while (cursor.moveToNext());
|
|
|
}
|
|
|
}
|
|
|
@@ -167,6 +142,39 @@ public class MediaUtils {
|
|
|
return mediaBeanList;
|
|
|
}
|
|
|
|
|
|
+ private static void checkImgMediaBean(MediaBean item) {
|
|
|
+ //检查并重新设置宽高
|
|
|
+ if (item != null && item.getOriginalPath() != null) {
|
|
|
+ if (item.getHeight() <= 0 || item.getWidth() <= 0) {
|
|
|
+ BitmapFactory.Options options = getImageOptions(item.getOriginalPath());
|
|
|
+ item.setWidth(options.outWidth);
|
|
|
+ item.setHeight(options.outHeight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void checkVideoMediaBean(Context context, MediaBean item) {
|
|
|
+ //检查并重新设置宽高
|
|
|
+ if (item != null && item.getOriginalPath() != null) {
|
|
|
+ if (item.getHeight() <= 0 || item.getWidth() <= 0 || item.getOrientation() == -1) {
|
|
|
+ try {
|
|
|
+ MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
|
|
|
+ metadataRetriever.setDataSource(context, Uri.parse(item.getOriginalPath()));
|
|
|
+ String width = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); // 视频宽度
|
|
|
+ String height = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); // 视频高度
|
|
|
+ String rotation = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); // 视频旋转方向
|
|
|
+
|
|
|
+ item.setWidth(Float.valueOf(width).intValue());
|
|
|
+ item.setHeight(Float.valueOf(height).intValue());
|
|
|
+ item.setOrientation(Float.valueOf(rotation).intValue());
|
|
|
+ LogUtil.println("getMediaWithVideoList", width, height, rotation);
|
|
|
+ } catch (Exception e){
|
|
|
+ LogUtil.println("getMediaWithVideoList", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据原图获取图片相关信息
|
|
|
*/
|
|
|
@@ -196,6 +204,7 @@ public class MediaUtils {
|
|
|
if (cursor != null && cursor.getCount() > 0) {
|
|
|
cursor.moveToFirst();
|
|
|
mediaBean = parseImageCursorAndCreateThumImage(context, cursor);
|
|
|
+ checkImgMediaBean(mediaBean);
|
|
|
}
|
|
|
if (cursor != null && !cursor.isClosed()) {
|
|
|
cursor.close();
|
|
|
@@ -234,6 +243,7 @@ public class MediaUtils {
|
|
|
if (cursor != null && cursor.getCount() > 0) {
|
|
|
cursor.moveToFirst();
|
|
|
mediaBean = parseVideoCursorAndCreateThumImage(context, cursor);
|
|
|
+ checkVideoMediaBean(context, mediaBean);
|
|
|
}
|
|
|
if (cursor != null && !cursor.isClosed()) {
|
|
|
cursor.close();
|