Skip to content

Commit

Permalink
add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
duzexu committed Nov 20, 2024
1 parent e50cc07 commit 5254e77
Show file tree
Hide file tree
Showing 30 changed files with 801 additions and 39 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
9 changes: 5 additions & 4 deletions ADPhotoKit/Classes/Base/ADPhotoKitConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,15 @@ public class ADPhotoKitConfiguration {
public var systemVideoEditTools: ADVideoEditTools = .all

/// User custom video edit tools. Custom tools is default add after system tools.
public var customVideoEditToolsBlock: (() -> [ADVideoEditTool])?

/// Custom video edit controller.
public var customVideoEditVCBlock: ((ADPhotoKitConfig, AVAsset, ADVideoEditInfo?) -> ADVideoEditConfigurable)?
/// - Note: Usually when you add a custom `ADVideoEditTool`, you need to set `customVideoPlayable` at the same time to respond to the modification of the corresponding tool.
public var customVideoEditToolsBlock: ((AVAsset) -> [ADVideoEditTool])?

/// Custom video player.
public var customVideoPlayable: ADVideoPlayable.Type?

/// Custom video edit controller.
public var customVideoEditVCBlock: ((ADPhotoKitConfig, AVAsset, ADVideoEditInfo?) -> ADVideoEditConfigurable)?

/* =============== bgm =============== */

/// System video bgm data source.
Expand Down
2 changes: 1 addition & 1 deletion ADPhotoKit/Classes/Base/ADPhotoKitConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let screenBounds:CGRect = { return UIScreen.main.bounds }()
let screenWidth:CGFloat = { return UIScreen.main.bounds.size.width }()
let screenHeight:CGFloat = { return UIScreen.main.bounds.size.height }()

///包含 iPhone12 mini
/// 包含 iPhone12 mini
let isPhoneXOrLater:Bool = { return isPhone && screenHeight >= 812.0 }()

let statusBarHeight: CGFloat = UIApplication.shared.statusBarFrame.height
Expand Down
2 changes: 2 additions & 0 deletions ADPhotoKit/Classes/Core/Extension/ADImageDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public class ADAssetImageDataProvider: ImageDataProvider {
guard let strong = self else { return }
if let av = asset as? AVAsset {
let generator = AVAssetImageGenerator(asset: av)
generator.appliesPreferredTrackTransform = true
generator.apertureMode = .encodedPixels
generator.generateCGImagesAsynchronously(forTimes: [NSValue(time: strong.time)]) {
(requestedTime, image, imageTime, result, error) in
if let error = error {
Expand Down
3 changes: 2 additions & 1 deletion ADPhotoKit/Classes/Core/Extension/AVAsset+ADExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import AVFoundation

extension AVAsset {

var naturalSize: CGSize {
/// Return asset naturalSize.
public var naturalSize: CGSize {
if let videoTrack = tracks(withMediaType: .video).first {
var size = videoTrack.naturalSize
if AVAsset.isPortraitTrack(videoTrack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public class ADBrowserToolBarCell: UICollectionViewCell {
if model.imageEditInfo != nil {
imageView.image = model.imageEditInfo?.editImg
tagImageView.isHidden = false
tagImageView.image = Bundle.image(name: "EditedIcon_Normal", module: .imageEdit)
tagImageView.image = Bundle.image(name: "ImageEditedIcon", module: .imageEdit)
return
}
#endif
#if Module_VideoEdit
if model.videoEditInfo != nil {
imageView.image = model.videoEditInfo?.editThumbnail
tagImageView.isHidden = false
tagImageView.image = Bundle.image(name: "EditedIcon_Normal", module: .videoEdit)
tagImageView.image = Bundle.image(name: "VideoEditedIcon", module: .videoEdit)
return
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ extension ADThumbnailListCell: ADThumbnailCellConfigurable {
descLabel.text = ""
imageView.image = imageEdit
bottomMaskView.isHidden = false
tagImageView.image = Bundle.image(name: "EditedIcon_Normal", module: .imageEdit)
tagImageView.image = Bundle.image(name: "ImageEditedIcon", module: .imageEdit)
return
}
#endif
#if Module_VideoEdit
if let videoEdit = model.videoEditInfo?.editThumbnail {
imageView.image = videoEdit
bottomMaskView.isHidden = false
tagImageView.image = Bundle.image(name: "EditedIcon_Normal", module: .videoEdit)
tagImageView.image = Bundle.image(name: "VideoEditedIcon", module: .videoEdit)
return
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions ADPhotoKit/Classes/EditCore/View/ADEditControlsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ extension ADEditControlsView: UICollectionViewDataSource, UICollectionViewDelega
selectToolIndex = nil
}else if tool.toolDidSelect(ctx: vc) {
selectToolIndex = indexPath.row
}else{
selectToolIndex = nil
}
}
}
8 changes: 8 additions & 0 deletions ADPhotoKit/Classes/VideoEdit/ADMusicSelectController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public class ADVideoSound {
public var bgm: ADMusicItem? = nil
/// Whether bgm loop play.
public var bgmLoop: Bool = true

/// Create video sound.
public init(lyricOn: Bool = false, ostOn: Bool = true, bgm: ADMusicItem? = nil, bgmLoop: Bool = true) {
self.lyricOn = lyricOn
self.ostOn = ostOn
self.bgm = bgm
self.bgmLoop = bgmLoop
}
}

/// Music select datasource.
Expand Down
1 change: 1 addition & 0 deletions ADPhotoKit/Classes/VideoEdit/ADVideoEditConfigurable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public protocol ADVideoEditTool: ADEditTool {
var playableRectUpdate: ((CGFloat, CGFloat, Bool) -> Void)! { set get }

/// View to preview edit video.
/// - Note: This property is initialized and set by the system. Classes that implement this protocol should declare this property as weak.
var videoPlayable: ADVideoPlayable? { set get }

}
Expand Down
2 changes: 1 addition & 1 deletion ADPhotoKit/Classes/VideoEdit/ADVideoEditController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ extension ADVideoEditController {
let clip = ADVideoClip(asset: asset, min: min, max: max)
tools.append(clip)
}
if let custom = ADPhotoKitConfiguration.default.customVideoEditToolsBlock?() {
if let custom = ADPhotoKitConfiguration.default.customVideoEditToolsBlock?(asset) {
tools.append(contentsOf: custom)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import AVFoundation
import UIKit

class ADVideoThumbnailOperation: Operation {

Expand Down
1 change: 1 addition & 0 deletions ADPhotoKit/Classes/VideoEdit/Tools/ADVideoBGM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit

class ADVideoBGM: ADVideoEditTool {

Expand Down
1 change: 1 addition & 0 deletions ADPhotoKit/Classes/VideoEdit/Tools/ADVideoClip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import AVFoundation
import UIKit

class ADVideoClip: ADVideoEditTool {

Expand Down
5 changes: 3 additions & 2 deletions ADPhotoKit/Classes/VideoEdit/Tools/ADVideoSticker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
//

import Foundation
import UIKit

class ADVideoSticker: ADVideoEditTool {

var image: UIImage {
switch style {
case .text:
return Bundle.image(name: "icons_filled_text", module: .videoEdit) ?? UIImage()
return Bundle.image(name: "video_filled_text", module: .videoEdit) ?? UIImage()
case .image:
return Bundle.image(name: "icons_filled_sticker", module: .videoEdit) ?? UIImage()
return Bundle.image(name: "video_filled_sticker", module: .videoEdit) ?? UIImage()
}
}

Expand Down
2 changes: 0 additions & 2 deletions ADPhotoKit/Classes/VideoEdit/View/ADVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ class ADVideoPlayerView: UIView, ADVideoPlayable {

private var progressObservers: [Observer] = []

private var videoSize: CGSize = .zero
private var player: AVPlayer!
private var videoPlayerLayer: AVPlayerLayer!

required init(asset: AVAsset) {
self.asset = asset
videoPlayerLayer = AVPlayerLayer()
super.init(frame: .zero)
videoSize = asset.naturalSize
player = AVPlayer()
videoPlayerLayer.contentsGravity = .resizeAspect
layer.insertSublayer(videoPlayerLayer, at: 0)
Expand Down
20 changes: 16 additions & 4 deletions Example/ADPhotoKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
810C016E2C522C6E0051AE90 /* CustomAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810C016D2C522C6E0051AE90 /* CustomAlertViewController.swift */; };
816183C52CBD0A3D00FE3D2D /* bgms in Resources */ = {isa = PBXBuildFile; fileRef = 816183C42CBD0A3D00FE3D2D /* bgms */; };
819662512CEC813D00922582 /* VideoFilterTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 819662502CEC813D00922582 /* VideoFilterTool.swift */; };
819662532CEC940400922582 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 819662522CEC940400922582 /* VideoPlayerView.swift */; };
819662552CED748700922582 /* VideoExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 819662542CED748700922582 /* VideoExporter.swift */; };
81D9AA9A2B6A433000CE472F /* SwiftUIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81D9AA992B6A433000CE472F /* SwiftUIViewController.swift */; };
81D9AA9D2B6A44C700CE472F /* MainSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81D9AA9C2B6A44C700CE472F /* MainSwiftUIView.swift */; };
81D9AA9F2B6A45CC00CE472F /* DemosViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81D9AA9E2B6A45CC00CE472F /* DemosViewController.swift */; };
Expand Down Expand Up @@ -96,7 +99,7 @@
95792A9026579AA300AE8ED5 /* VideoBrowserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95792A8E26579AA300AE8ED5 /* VideoBrowserCell.swift */; };
95792A9126579AA300AE8ED5 /* VideoBrowserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 95792A8F26579AA300AE8ED5 /* VideoBrowserCell.xib */; };
9582CACC26F338C100C250E7 /* ImageFilterTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9582CACB26F338C100C250E7 /* ImageFilterTool.swift */; };
9582CACE26F33B1700C250E7 /* ImageFilterSelectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9582CACD26F33B1700C250E7 /* ImageFilterSelectView.swift */; };
9582CACE26F33B1700C250E7 /* FilterSelectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9582CACD26F33B1700C250E7 /* FilterSelectView.swift */; };
BFEB069A60BB41EC33CB7F50 /* Pods_ADPhotoKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24853DA6C7C8D2739F567EE4 /* Pods_ADPhotoKit_Example.framework */; };
/* End PBXBuildFile section */

Expand All @@ -115,6 +118,9 @@
781C69769B128467B470C297 /* ADPhotoKit.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = ADPhotoKit.podspec; path = ../ADPhotoKit.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
810C016D2C522C6E0051AE90 /* CustomAlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertViewController.swift; sourceTree = "<group>"; };
816183C42CBD0A3D00FE3D2D /* bgms */ = {isa = PBXFileReference; lastKnownFileType = folder; path = bgms; sourceTree = "<group>"; };
819662502CEC813D00922582 /* VideoFilterTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoFilterTool.swift; sourceTree = "<group>"; };
819662522CEC940400922582 /* VideoPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayerView.swift; sourceTree = "<group>"; };
819662542CED748700922582 /* VideoExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoExporter.swift; sourceTree = "<group>"; };
81D9AA992B6A433000CE472F /* SwiftUIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIViewController.swift; sourceTree = "<group>"; };
81D9AA9C2B6A44C700CE472F /* MainSwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainSwiftUIView.swift; sourceTree = "<group>"; };
81D9AA9E2B6A45CC00CE472F /* DemosViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemosViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -197,7 +203,7 @@
95792A8E26579AA300AE8ED5 /* VideoBrowserCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoBrowserCell.swift; sourceTree = "<group>"; };
95792A8F26579AA300AE8ED5 /* VideoBrowserCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = VideoBrowserCell.xib; sourceTree = "<group>"; };
9582CACB26F338C100C250E7 /* ImageFilterTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageFilterTool.swift; sourceTree = "<group>"; };
9582CACD26F33B1700C250E7 /* ImageFilterSelectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageFilterSelectView.swift; sourceTree = "<group>"; };
9582CACD26F33B1700C250E7 /* FilterSelectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterSelectView.swift; sourceTree = "<group>"; };
95CADD19265CD0A100009D1B /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Package.swift; sourceTree = "<group>"; };
A1D674AD92CA2F57D0C42C9D /* Pods-ADPhotoKit_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ADPhotoKit_Tests.release.xcconfig"; path = "Target Support Files/Pods-ADPhotoKit_Tests/Pods-ADPhotoKit_Tests.release.xcconfig"; sourceTree = "<group>"; };
AD6AD32727AAE9474B8F3EE1 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -422,7 +428,10 @@
isa = PBXGroup;
children = (
9582CACB26F338C100C250E7 /* ImageFilterTool.swift */,
9582CACD26F33B1700C250E7 /* ImageFilterSelectView.swift */,
9582CACD26F33B1700C250E7 /* FilterSelectView.swift */,
819662502CEC813D00922582 /* VideoFilterTool.swift */,
819662522CEC940400922582 /* VideoPlayerView.swift */,
819662542CED748700922582 /* VideoExporter.swift */,
);
name = Edit;
sourceTree = "<group>";
Expand Down Expand Up @@ -638,16 +647,19 @@
81D9AA9F2B6A45CC00CE472F /* DemosViewController.swift in Sources */,
95792A402657675A00AE8ED5 /* BrowserNavBar.swift in Sources */,
9522FB332655133D00A0D360 /* ProgressHUD.swift in Sources */,
819662532CEC940400922582 /* VideoPlayerView.swift in Sources */,
9551F0B9263C0AF10089C8DE /* Stepper.swift in Sources */,
9551F0B2263BA9130089C8DE /* ConfigModel.swift in Sources */,
9582CACE26F33B1700C250E7 /* ImageFilterSelectView.swift in Sources */,
9582CACE26F33B1700C250E7 /* FilterSelectView.swift in Sources */,
9551F0B6263BACB70089C8DE /* ConfigCell.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
819662512CEC813D00922582 /* VideoFilterTool.swift in Sources */,
81D9AA9D2B6A44C700CE472F /* MainSwiftUIView.swift in Sources */,
81D9AA9A2B6A433000CE472F /* SwiftUIViewController.swift in Sources */,
95792A9026579AA300AE8ED5 /* VideoBrowserCell.swift in Sources */,
95792A2926563F2200AE8ED5 /* AlbumCell.swift in Sources */,
810C016E2C522C6E0051AE90 /* CustomAlertViewController.swift in Sources */,
819662552CED748700922582 /* VideoExporter.swift in Sources */,
95792A8B26579A9200AE8ED5 /* ImageBrowserCell.swift in Sources */,
9582CACC26F338C100C250E7 /* ImageFilterTool.swift in Sources */,
9551F0A7263A98D80089C8DE /* LanguageViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import UIKit
import ADPhotoKit

#if Module_ImageEdit
class ImageFilterSelectView: UIView, ADToolConfigable {
#if Module_ImageEdit || Module_VideoEdit
class FilterSelectView: UIView, ADToolConfigable {

weak var dataSource: (UICollectionViewDataSource & UICollectionViewDelegate)?

Expand Down
10 changes: 5 additions & 5 deletions Example/ADPhotoKit/ImageFilterTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import ADPhotoKit

#if Module_ImageEdit
enum Filter: CaseIterable {
enum ImageFilter: CaseIterable {
case none
case chrome
case fade
Expand Down Expand Up @@ -133,13 +133,13 @@ class ImageFilterTool: NSObject, ADImageEditTool, ADSourceImageEditable {
var filterImages: [UIImage] = []
var selectIndex: Int = -1

init(image: UIImage, filters: [Filter] = Filter.allCases) {
init(image: UIImage, filters: [ImageFilter] = ImageFilter.allCases) {
originImage = image
super.init()

let thumbnail = generateThumbnailImage(img: image) ?? image

let selectV = ImageFilterSelectView(dataSource: self)
let selectV = FilterSelectView(dataSource: self)
toolConfigView = selectV

DispatchQueue.global().async {
Expand Down Expand Up @@ -172,14 +172,14 @@ class ImageFilterTool: NSObject, ADImageEditTool, ADSourceImageEditable {

func indexDidChange() {
guard selectIndex >= 0 else {
(toolConfigView as? ImageFilterSelectView)?.collectionView.reloadData()
(toolConfigView as? FilterSelectView)?.collectionView.reloadData()
modifySourceImage?(originImage)
return
}
guard selectIndex < filterImages.count else {
return
}
(toolConfigView as? ImageFilterSelectView)?.collectionView.reloadData()
(toolConfigView as? FilterSelectView)?.collectionView.reloadData()
modifySourceImage?(filterImages[selectIndex])
}

Expand Down
Loading

0 comments on commit 5254e77

Please sign in to comment.