Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto trim for videos from device library using trimmerMaxDuration #515

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OS X
.DS_Store

# AppCode
.idea/

# Xcode
build/
*.pbxuser
Expand Down
108 changes: 57 additions & 51 deletions Source/Configuration/YPImagePickerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,86 +16,86 @@ internal var YPConfig: YPImagePickerConfiguration { return YPImagePickerConfigur

public struct YPImagePickerConfiguration {
public static var shared: YPImagePickerConfiguration = YPImagePickerConfiguration()

public init() {}

/// Scroll to change modes, defaults to true
public var isScrollToChangeModesEnabled = true

// Library configuration
public var library = YPConfigLibrary()

// Video configuration
public var video = YPConfigVideo()

// Gallery configuration
public var gallery = YPConfigSelectionsGallery()

/// Use this property to modify the default wordings provided.
public var wordings = YPWordings()

/// Use this property to modify the default icons provided.
public var icons = YPIcons()

/// Use this property to modify the default colors provided.
public var colors = YPColors()

/// Set this to true if you want to force the camera output to be a squared image. Defaults to true
public var onlySquareImagesFromCamera = true

/// Enables selecting the front camera by default, useful for avatars. Defaults to false
public var usesFrontCamera = false

/// Adds a Filter step in the photo taking process. Defaults to true
public var showsPhotoFilters = true

/// Adds a Video Trimmer step in the video taking process. Defaults to true
public var showsVideoTrimmer = true

/// Enables you to opt out from saving new (or old but filtered) images to the
/// user's photo library. Defaults to true.
public var shouldSaveNewPicturesToAlbum = true

/// Defines the name of the album when saving pictures in the user's photo library.
/// In general that would be your App name. Defaults to "DefaultYPImagePickerAlbumName"
public var albumName = "DefaultYPImagePickerAlbumName"

/// Defines which screen is shown at launch. Video mode will only work if `showsVideo = true`.
/// Default value is `.photo`
public var startOnScreen: YPPickerScreen = .photo

/// Defines which screens are shown at launch, and their order.
/// Default value is `[.library, .photo]`
public var screens: [YPPickerScreen] = [.library, .photo]

/// Adds a Crop step in the photo taking process, after filters. Defaults to .none
public var showsCrop: YPCropType = .none

/// Ex: cappedTo:1024 will make sure images from the library or the camera will be
/// resized to fit in a 1024x1024 box. Defaults to original image size.
public var targetImageSize = YPImageSize.original

/// Adds a Overlay View to the camera
public var overlayView: UIView?

/// Defines if the status bar should be hidden when showing the picker. Default is true
public var hidesStatusBar = true

/// Defines if the bottom bar should be hidden when showing the picker. Default is false.
public var hidesBottomBar = false

/// Defines the preferredStatusBarAppearance
public var preferredStatusBarStyle = UIStatusBarStyle.default

/// Defines the text colour to be shown when a bottom option is selected
public var bottomMenuItemSelectedTextColour: UIColor = .ypLabel

/// Defines the text colour to be shown when a bottom option is unselected
public var bottomMenuItemUnSelectedTextColour: UIColor = .ypSecondaryLabel

/// Defines the max camera zoom factor for camera. Disable camera zoom with 1. Default is 1.
public var maxCameraZoomFactor: CGFloat = 1.0

/// List of default filters which will be added on the filter screen
public var filters: [YPFilter] = [
YPFilter(name: "Normal", applier: nil),
Expand All @@ -116,64 +116,64 @@ public struct YPImagePickerConfiguration {
YPFilter(name: "Linear", coreImageFilterName: "CISRGBToneCurveToLinear"),
YPFilter(name: "Sepia", coreImageFilterName: "CISepiaTone"),
]

/// Migration

@available(iOS, obsoleted: 3.0.0, renamed: "video.compression")
public var videoCompression: String = AVAssetExportPresetHighestQuality

@available(iOS, obsoleted: 3.0.0, renamed: "video.fileType")
public var videoExtension: AVFileType = .mov

@available(iOS, obsoleted: 3.0.0, renamed: "video.recordingTimeLimit")
public var videoRecordingTimeLimit: TimeInterval = 60.0

@available(iOS, obsoleted: 3.0.0, renamed: "video.libraryTimeLimit")
public var videoFromLibraryTimeLimit: TimeInterval = 60.0

@available(iOS, obsoleted: 3.0.0, renamed: "video.minimumTimeLimit")
public var videoMinimumTimeLimit: TimeInterval = 3.0

@available(iOS, obsoleted: 3.0.0, renamed: "video.trimmerMaxDuration")
public var trimmerMaxDuration: Double = 60.0

@available(iOS, obsoleted: 3.0.0, renamed: "video.trimmerMinDuration")
public var trimmerMinDuration: Double = 3.0

@available(iOS, obsoleted: 3.0.0, renamed: "library.onlySquare")
public var onlySquareImagesFromLibrary = false

@available(iOS, obsoleted: 3.0.0, renamed: "library.onlySquare")
public var onlySquareFromLibrary = false

@available(iOS, obsoleted: 3.0.0, renamed: "targetImageSize")
public var libraryTargetImageSize = YPImageSize.original

@available(iOS, obsoleted: 3.0.0, renamed: "library.mediaType")
public var showsVideoInLibrary = false

@available(iOS, obsoleted: 3.0.0, renamed: "library.mediaType")
public var libraryMediaType = YPlibraryMediaType.photo

@available(iOS, obsoleted: 3.0.0, renamed: "library.maxNumberOfItems")
public var maxNumberOfItems = 1

}

/// Encapsulates library specific settings.
public struct YPConfigLibrary {

public var options: PHFetchOptions? = nil

/// Set this to true if you want to force the library output to be a squared image. Defaults to false.
public var onlySquare = false

/// Sets the cropping style to square or not. Ignored if `onlySquare` is true. Defaults to true.
public var isSquareByDefault = true

/// Minimum width, to prevent selectiong too high images. Have sense if onlySquare is true and the image is portrait.
public var minWidthForItem: CGFloat?

/// Choose what media types are available in the library. Defaults to `.photo`
public var mediaType = YPlibraryMediaType.photo

Expand All @@ -182,7 +182,7 @@ public struct YPConfigLibrary {

/// Anything superior than 1 will enable the multiple selection feature.
public var maxNumberOfItems = 1

/// Anything greater than 1 will desactivate live photo and video modes (library only) and
// force users to select at least the number of items defined.
public var minNumberOfItems = 1
Expand All @@ -195,14 +195,14 @@ public struct YPConfigLibrary {

/// Allow to skip the selections gallery when selecting the multiple media items. Defaults to false.
public var skipSelectionsGallery = false

/// Allow to preselected media items
public var preselectedItems: [YPMediaItem]?
}

/// Encapsulates video specific settings.
public struct YPConfigVideo {

/** Choose the videoCompression. Defaults to AVAssetExportPresetHighestQuality
- "AVAssetExportPresetLowQuality"
- "AVAssetExportPreset640x480"
Expand All @@ -216,28 +216,34 @@ public struct YPConfigVideo {
- "AVAssetExportPresetPassthrough" // without any compression
*/
public var compression: String = AVAssetExportPresetHighestQuality

/// Choose the result video extension if you trim or compress a video. Defaults to mov.
public var fileType: AVFileType = .mov

/// Defines the time limit for recording videos.
/// Default is 60 seconds.
public var recordingTimeLimit: TimeInterval = 60.0

/// Defines the time limit for videos from the library.
/// Defaults to 60 seconds.
public var libraryTimeLimit: TimeInterval = 60.0

/// Defines the minimum time for the video
/// Defaults to 3 seconds.
public var minimumTimeLimit: TimeInterval = 3.0

/// The maximum duration allowed for the trimming. Change it before setting the asset, as the asset preview
/// - Tag: trimmerMaxDuration
public var trimmerMaxDuration: Double = 60.0

/// The minimum duration allowed for the trimming.
/// The handles won't pan further if the minimum duration is attained.
public var trimmerMinDuration: Double = 3.0

/// Defines if the user skips the trimer stage, the video will be trimmed automatically to the maximum value of trimmerMaxDuration
/// This case occurs when the user already has a video selected and enables a multiselection to pick more than one type of media (video or image), so, the trimmer step becomes optional.
/// - SeeAlso: [trimmerMaxDuration](x-source-tag://trimmerMaxDuration)
public var automaticTrimToTrimmerMaxDuration: Bool = false
}

/// Encapsulates gallery specific settings.
Expand Down