add size property of medium
This commit is contained in:
parent
dce3b48e90
commit
ab0f81607b
@ -60,6 +60,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
MediaStore.Images.Media.TITLE,
|
||||
MediaStore.Images.Media.WIDTH,
|
||||
MediaStore.Images.Media.HEIGHT,
|
||||
MediaStore.Images.Media.SIZE,
|
||||
MediaStore.Images.Media.ORIENTATION,
|
||||
MediaStore.Images.Media.MIME_TYPE,
|
||||
MediaStore.Images.Media.DATE_TAKEN,
|
||||
@ -72,6 +73,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
MediaStore.Video.Media.TITLE,
|
||||
MediaStore.Video.Media.WIDTH,
|
||||
MediaStore.Video.Media.HEIGHT,
|
||||
MediaStore.Video.Media.SIZE,
|
||||
MediaStore.Video.Media.MIME_TYPE,
|
||||
MediaStore.Video.Media.DURATION,
|
||||
MediaStore.Video.Media.DATE_TAKEN,
|
||||
@ -804,6 +806,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val titleColumn = cursor.getColumnIndex(MediaStore.Images.Media.TITLE)
|
||||
val widthColumn = cursor.getColumnIndex(MediaStore.Images.Media.WIDTH)
|
||||
val heightColumn = cursor.getColumnIndex(MediaStore.Images.Media.HEIGHT)
|
||||
val sizeColumn = cursor.getColumnIndex(MediaStore.Images.Media.SIZE)
|
||||
val orientationColumn = cursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION)
|
||||
val mimeColumn = cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE)
|
||||
val dateTakenColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN)
|
||||
@ -814,6 +817,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val title = cursor.getString(titleColumn)
|
||||
val width = cursor.getLong(widthColumn)
|
||||
val height = cursor.getLong(heightColumn)
|
||||
val size = cursor.getLong(sizeColumn)
|
||||
val orientation = cursor.getLong(orientationColumn)
|
||||
val mimeType = cursor.getString(mimeColumn)
|
||||
var dateTaken: Long? = null
|
||||
@ -832,6 +836,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
"mediumType" to imageType,
|
||||
"width" to width,
|
||||
"height" to height,
|
||||
"size" to size,
|
||||
"orientation" to orientationDegree2Value(orientation),
|
||||
"mimeType" to mimeType,
|
||||
"creationDate" to dateTaken,
|
||||
@ -845,6 +850,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val titleColumn = cursor.getColumnIndex(MediaStore.Video.Media.TITLE)
|
||||
val widthColumn = cursor.getColumnIndex(MediaStore.Video.Media.WIDTH)
|
||||
val heightColumn = cursor.getColumnIndex(MediaStore.Video.Media.HEIGHT)
|
||||
val sizeColumn = cursor.getColumnIndex(MediaStore.Video.Media.SIZE)
|
||||
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)
|
||||
@ -855,6 +861,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
val title = cursor.getString(titleColumn)
|
||||
val width = cursor.getLong(widthColumn)
|
||||
val height = cursor.getLong(heightColumn)
|
||||
val size = cursor.getLong(sizeColumn)
|
||||
val mimeType = cursor.getString(mimeColumn)
|
||||
val duration = cursor.getLong(durationColumn)
|
||||
var dateTaken: Long? = null
|
||||
@ -873,6 +880,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
"mediumType" to videoType,
|
||||
"width" to width,
|
||||
"height" to height,
|
||||
"size" to size,
|
||||
"mimeType" to mimeType,
|
||||
"duration" to duration,
|
||||
"creationDate" to dateTaken,
|
||||
|
@ -417,6 +417,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
private func getMediumFromAsset(asset: PHAsset) -> [String: Any?] {
|
||||
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
||||
let filename = self.extractFilenameFromAsset(asset: asset)
|
||||
let size = self.extractSizeFromAsset(asset: asset)
|
||||
return [
|
||||
"id": asset.localIdentifier,
|
||||
"filename": filename,
|
||||
@ -425,6 +426,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
"mimeType": mimeType,
|
||||
"height": asset.pixelHeight,
|
||||
"width": asset.pixelWidth,
|
||||
"size": size,
|
||||
"duration": NSInteger(asset.duration * 1000),
|
||||
"creationDate": (asset.creationDate != nil) ? NSInteger(asset.creationDate!.timeIntervalSince1970 * 1000) : nil,
|
||||
"modifiedDate": (asset.modificationDate != nil) ? NSInteger(asset.modificationDate!.timeIntervalSince1970 * 1000) : nil
|
||||
@ -434,6 +436,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
private func getMediumFromAssetAsync(asset: PHAsset, completion: @escaping ([String : Any?]?, Error?) -> Void) -> Void {
|
||||
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
||||
let filename = self.extractFilenameFromAsset(asset: asset)
|
||||
let size = self.extractSizeFromAsset(asset: asset)
|
||||
let manager = PHImageManager.default()
|
||||
manager.requestImageData(
|
||||
for: asset,
|
||||
@ -447,6 +450,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
"mimeType": mimeType,
|
||||
"height": asset.pixelHeight,
|
||||
"width": asset.pixelWidth,
|
||||
"size": size,
|
||||
"orientation": self.toOrientationValue(orientation: orientation),
|
||||
"duration": NSInteger(asset.duration * 1000),
|
||||
"creationDate": (asset.creationDate != nil) ? NSInteger(asset.creationDate!.timeIntervalSince1970 * 1000) : nil,
|
||||
@ -566,6 +570,15 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
}
|
||||
return asset.value(forKey: "filename") as? String
|
||||
}
|
||||
|
||||
private func extractSizeFromAsset(asset: PHAsset) -> Int64? {
|
||||
let resources = PHAssetResource.assetResources(for: asset)
|
||||
guard let resource = resources.first,
|
||||
let unsignedInt64 = resource.value(forKey: "fileSize") as? CLong else {
|
||||
return nil
|
||||
}
|
||||
return Int64(bitPattern: UInt64(unsignedInt64))
|
||||
}
|
||||
|
||||
private func extractTitleFromFilename(filename: String?) -> String? {
|
||||
if let name = filename {
|
||||
|
@ -23,6 +23,9 @@ class Medium {
|
||||
/// The medium height.
|
||||
final int? height;
|
||||
|
||||
/// The medium size.
|
||||
final int? size;
|
||||
|
||||
/// The medium orientation.
|
||||
final int? orientation;
|
||||
|
||||
@ -45,6 +48,7 @@ class Medium {
|
||||
this.mediumType,
|
||||
this.width,
|
||||
this.height,
|
||||
this.size,
|
||||
this.orientation = 0,
|
||||
this.mimeType,
|
||||
this.duration = 0,
|
||||
@ -60,6 +64,7 @@ class Medium {
|
||||
mediumType = jsonToMediumType(json["mediumType"]),
|
||||
width = json["width"],
|
||||
height = json["height"],
|
||||
size = json["size"],
|
||||
orientation = json["orientation"],
|
||||
mimeType = json["mimeType"],
|
||||
duration = json['duration'] ?? 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user