From 32129c5e9e965f9beeaa269291fd0759acfd3bbe Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Tue, 18 Aug 2020 16:12:06 +0800 Subject: [PATCH] add video duration attribute in Medium --- .../kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt | 4 ++++ ios/Classes/SwiftPhotoGalleryPlugin.swift | 1 + lib/src/models/medium.dart | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt b/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt index 0844f23..038cd65 100644 --- a/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt +++ b/android/src/main/kotlin/com/morbit/photogallery/PhotoGalleryPlugin.kt @@ -63,6 +63,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler { MediaStore.Video.Media._ID, MediaStore.Video.Media.WIDTH, MediaStore.Video.Media.HEIGHT, + MediaStore.Video.Media.DURATION, MediaStore.Video.Media.DATE_TAKEN, MediaStore.Video.Media.DATE_MODIFIED ) @@ -580,12 +581,14 @@ 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 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) val id = cursor.getLong(idColumn) val width = cursor.getLong(widthColumn) val height = cursor.getLong(heightColumn) + val duration = cursor.getLong(durationColumn) var dateTaken: Long? = null if (cursor.getType(dateTakenColumn) == FIELD_TYPE_INTEGER) { dateTaken = cursor.getLong(dateTakenColumn) @@ -600,6 +603,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler { "mediumType" to videoType, "width" to width, "height" to height, + "duration" to duration, "creationDate" to dateTaken, "modifiedDate" to dateModified ) diff --git a/ios/Classes/SwiftPhotoGalleryPlugin.swift b/ios/Classes/SwiftPhotoGalleryPlugin.swift index 13aa507..e7498e5 100644 --- a/ios/Classes/SwiftPhotoGalleryPlugin.swift +++ b/ios/Classes/SwiftPhotoGalleryPlugin.swift @@ -371,6 +371,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin { "mediumType": toDartMediumType(value: asset.mediaType), "height": asset.pixelHeight, "width": asset.pixelWidth, + "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 ] diff --git a/lib/src/models/medium.dart b/lib/src/models/medium.dart index 7f41ffd..f5a08c6 100644 --- a/lib/src/models/medium.dart +++ b/lib/src/models/medium.dart @@ -17,6 +17,9 @@ class Medium { /// The medium height. final int height; + /// The duration of video + final int duration; + /// The date at which the photo or video was taken. final DateTime creationDate; @@ -28,6 +31,7 @@ class Medium { this.mediumType, this.width, this.height, + this.duration, this.creationDate, this.modifiedDate, }); @@ -38,6 +42,7 @@ class Medium { mediumType = jsonToMediumType(json["mediumType"]), width = json["width"], height = json["height"], + duration = json['duration'] ?? 0, creationDate = json['creationDate'] != null ? DateTime.fromMillisecondsSinceEpoch(json['creationDate']) : null,