add mimeType attribute in Medium
This commit is contained in:
parent
5ddd31fed9
commit
a44d9da2ea
@ -56,6 +56,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
MediaStore.Images.Media._ID,
|
||||
MediaStore.Images.Media.WIDTH,
|
||||
MediaStore.Images.Media.HEIGHT,
|
||||
MediaStore.Images.Media.MIME_TYPE,
|
||||
MediaStore.Images.Media.DATE_TAKEN,
|
||||
MediaStore.Images.Media.DATE_MODIFIED
|
||||
)
|
||||
@ -64,6 +65,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
MediaStore.Video.Media._ID,
|
||||
MediaStore.Video.Media.WIDTH,
|
||||
MediaStore.Video.Media.HEIGHT,
|
||||
MediaStore.Video.Media.MIME_TYPE,
|
||||
MediaStore.Video.Media.DURATION,
|
||||
MediaStore.Video.Media.DATE_TAKEN,
|
||||
MediaStore.Video.Media.DATE_MODIFIED
|
||||
@ -587,12 +589,14 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID)
|
||||
val widthColumn = cursor.getColumnIndex(MediaStore.Images.Media.WIDTH)
|
||||
val heightColumn = cursor.getColumnIndex(MediaStore.Images.Media.HEIGHT)
|
||||
val mimeColumn = cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE)
|
||||
val dateTakenColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN)
|
||||
val dateModifiedColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)
|
||||
|
||||
val id = cursor.getLong(idColumn)
|
||||
val width = cursor.getLong(widthColumn)
|
||||
val height = cursor.getLong(heightColumn)
|
||||
val mimeType = cursor.getString(mimeColumn)
|
||||
var dateTaken: Long? = null
|
||||
if (cursor.getType(dateTakenColumn) == FIELD_TYPE_INTEGER) {
|
||||
dateTaken = cursor.getLong(dateTakenColumn)
|
||||
@ -607,6 +611,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
"mediumType" to imageType,
|
||||
"width" to width,
|
||||
"height" to height,
|
||||
"mimeType" to mimeType,
|
||||
"creationDate" to dateTaken,
|
||||
"modifiedDate" to dateModified
|
||||
)
|
||||
@ -616,6 +621,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID)
|
||||
val widthColumn = cursor.getColumnIndex(MediaStore.Video.Media.WIDTH)
|
||||
val heightColumn = cursor.getColumnIndex(MediaStore.Video.Media.HEIGHT)
|
||||
val mimeColumn = cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)
|
||||
val durationColumn = cursor.getColumnIndex(MediaStore.Video.Media.DURATION)
|
||||
val dateTakenColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN)
|
||||
val dateModifiedColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATE_MODIFIED)
|
||||
@ -623,6 +629,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val id = cursor.getLong(idColumn)
|
||||
val width = cursor.getLong(widthColumn)
|
||||
val height = cursor.getLong(heightColumn)
|
||||
val mimeType = cursor.getString(mimeColumn)
|
||||
val duration = cursor.getLong(durationColumn)
|
||||
var dateTaken: Long? = null
|
||||
if (cursor.getType(dateTakenColumn) == FIELD_TYPE_INTEGER) {
|
||||
@ -638,6 +645,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
"mediumType" to videoType,
|
||||
"width" to width,
|
||||
"height" to height,
|
||||
"mimeType" to mimeType,
|
||||
"duration" to duration,
|
||||
"creationDate" to dateTaken,
|
||||
"modifiedDate" to dateModified
|
||||
|
@ -376,9 +376,11 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
}
|
||||
|
||||
private func getMediumFromAsset(asset: PHAsset) -> [String: Any?] {
|
||||
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
||||
return [
|
||||
"id": asset.localIdentifier,
|
||||
"mediumType": toDartMediumType(value: asset.mediaType),
|
||||
"mimeType": mimeType,
|
||||
"height": asset.pixelHeight,
|
||||
"width": asset.pixelWidth,
|
||||
"duration": NSInteger(asset.duration * 1000),
|
||||
@ -435,6 +437,16 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
return "." + ext
|
||||
}
|
||||
|
||||
private func extractMimeTypeFromUTI(uti: String?) -> String? {
|
||||
guard let assetUTI = uti else {
|
||||
return nil
|
||||
}
|
||||
guard let mimeType = UTTypeCopyPreferredTagWithClass(assetUTI as CFString, kUTTagClassMIMEType as CFString)?.takeRetainedValue() as String? else {
|
||||
return nil
|
||||
}
|
||||
return mimeType
|
||||
}
|
||||
|
||||
private func extractUTIFromAsset(asset: PHAsset) -> String? {
|
||||
if #available(iOS 9, *) {
|
||||
let resourceList = PHAssetResource.assetResources(for: asset)
|
||||
@ -450,6 +462,11 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
return self.extractFileExtensionFromUTI(uti: uti)
|
||||
}
|
||||
|
||||
private func extractMimeTypeFromAsset(asset: PHAsset) -> String? {
|
||||
let uti = self.extractUTIFromAsset(asset: asset)
|
||||
return self.extractMimeTypeFromUTI(uti: uti)
|
||||
}
|
||||
|
||||
private func cachePath() -> URL {
|
||||
let paths = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
|
||||
let cacheFolder = paths[0].appendingPathComponent("photo_gallery")
|
||||
|
@ -17,6 +17,9 @@ class Medium {
|
||||
/// The medium height.
|
||||
final int height;
|
||||
|
||||
/// The medium mimeType.
|
||||
final String mimeType;
|
||||
|
||||
/// The duration of video
|
||||
final int duration;
|
||||
|
||||
@ -31,6 +34,7 @@ class Medium {
|
||||
this.mediumType,
|
||||
this.width,
|
||||
this.height,
|
||||
this.mimeType,
|
||||
this.duration,
|
||||
this.creationDate,
|
||||
this.modifiedDate,
|
||||
@ -42,6 +46,7 @@ class Medium {
|
||||
mediumType = jsonToMediumType(json["mediumType"]),
|
||||
width = json["width"],
|
||||
height = json["height"],
|
||||
mimeType = json["mimeType"],
|
||||
duration = json['duration'] ?? 0,
|
||||
creationDate = json['creationDate'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(json['creationDate'])
|
||||
@ -56,6 +61,7 @@ class Medium {
|
||||
mediumType: jsonToMediumType(map['mediumType']),
|
||||
width: map['width'],
|
||||
height: map['height'],
|
||||
mimeType: map["mimeType"],
|
||||
creationDate: map['creationDate'],
|
||||
modifiedDate: map['modifiedDate'],
|
||||
);
|
||||
@ -66,6 +72,7 @@ class Medium {
|
||||
"id": this.id,
|
||||
"mediumType": mediumTypeToJson(this.mediumType),
|
||||
"height": this.height,
|
||||
"mimeType": this.mimeType,
|
||||
"width": this.width,
|
||||
"creationDate": this.creationDate,
|
||||
"modifiedDate": this.modifiedDate,
|
||||
@ -104,6 +111,7 @@ class Medium {
|
||||
mediumType == other.mediumType &&
|
||||
width == other.width &&
|
||||
height == other.height &&
|
||||
mimeType == other.mimeType &&
|
||||
creationDate == other.creationDate &&
|
||||
modifiedDate == other.modifiedDate;
|
||||
|
||||
@ -113,6 +121,7 @@ class Medium {
|
||||
mediumType.hashCode ^
|
||||
width.hashCode ^
|
||||
height.hashCode ^
|
||||
mimeType.hashCode ^
|
||||
creationDate.hashCode ^
|
||||
modifiedDate.hashCode;
|
||||
|
||||
@ -122,6 +131,7 @@ class Medium {
|
||||
'mediumType: $mediumType, '
|
||||
'width: $width, '
|
||||
'height: $height, '
|
||||
'mimeType: $mimeType, '
|
||||
'creationDate: $creationDate, '
|
||||
'modifiedDate: $modifiedDate}';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user