Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ABVideoRangeSlider.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

Pod::Spec.new do |s|
s.name = 'ABVideoRangeSlider'
s.version = '0.1.5'
s.summary = 'A simple range slider for trimming videos written in Swift 3. Includes a Progress Indicator.'
s.version = '0.1.6'
s.summary = 'A simple range slider for trimming videos written in Swift 4. Includes a Progress Indicator.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand All @@ -20,13 +20,12 @@ Pod::Spec.new do |s|
s.description = 'Display thumbnails and a slider for trimming videos in iOS. Includes a Progress Indicator'

s.homepage = 'https://github.com/AppsBoulevard/ABVideoRangeSlider'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Oscar J. Irun' => '[email protected]' }
s.source = { :git => 'https://github.com/AppsBoulevard/ABVideoRangeSlider.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/AppsBoulevard'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '12.0'

s.source_files = 'ABVideoRangeSlider/Classes/**/*', 'ABVideoRangeSlider/Assets/*'

Expand Down
12 changes: 6 additions & 6 deletions ABVideoRangeSlider/Classes/ABBorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import UIKit
class ABBorder: UIView {

var imageView = UIImageView()

override init(frame: CGRect) {
super.init(frame: frame)

let bundle = Bundle(for: ABStartIndicator.self)
let image = UIImage(named: "BorderLine", in: bundle, compatibleWith: nil)

imageView.frame = self.bounds
imageView.image = image
imageView.contentMode = UIViewContentMode.scaleToFill
imageView.contentMode = .scaleToFill
self.addSubview(imageView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()
imageView.frame = self.bounds
Expand Down
14 changes: 7 additions & 7 deletions ABVideoRangeSlider/Classes/ABEndIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
import UIKit

class ABEndIndicator: UIView {

public var imageView = UIImageView()

override init(frame: CGRect) {
super.init(frame: frame)
self.isUserInteractionEnabled = true

let bundle = Bundle(for: ABStartIndicator.self)
let image = UIImage(named: "EndIndicator", in: bundle, compatibleWith: nil)

imageView.frame = self.bounds
imageView.image = image
imageView.contentMode = UIViewContentMode.scaleToFill
imageView.contentMode = .scaleToFill
self.addSubview(imageView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}
16 changes: 8 additions & 8 deletions ABVideoRangeSlider/Classes/ABProgressIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
import UIKit

class ABProgressIndicator: UIView {

var imageView = UIImageView()

override init(frame: CGRect) {
super.init(frame: frame)

let bundle = Bundle(for: ABStartIndicator.self)
let image = UIImage(named: "ProgressIndicator", in: bundle, compatibleWith: nil)
imageView.frame = self.bounds
imageView.image = image
imageView.contentMode = UIViewContentMode.scaleToFill
imageView.contentMode = .scaleToFill
self.addSubview(imageView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()
imageView.frame = self.bounds
Expand All @@ -37,9 +37,9 @@ class ABProgressIndicator: UIView {
y: 0,
width: self.frame.size.width * 2,
height: self.frame.size.height)
if frame.contains(point){
if frame.contains(point) {
return self
}else{
} else {
return nil
}
}
Expand Down
10 changes: 5 additions & 5 deletions ABVideoRangeSlider/Classes/ABStartIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import UIKit

class ABStartIndicator: UIView {

var imageView = UIImageView()

override init(frame: CGRect) {
super.init(frame: frame)
self.isUserInteractionEnabled = true

let bundle = Bundle(for: ABStartIndicator.self)
let image = UIImage(named: "StartIndicator", in: bundle, compatibleWith: nil)

imageView.frame = self.bounds
imageView.image = image
imageView.contentMode = UIViewContentMode.scaleToFill
imageView.contentMode = .scaleToFill
self.addSubview(imageView)
}

Expand Down
47 changes: 22 additions & 25 deletions ABVideoRangeSlider/Classes/ABThumbnailsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,69 @@ import UIKit
import AVFoundation

class ABThumbnailsManager: NSObject {

var thumbnailViews = [UIImageView]()

private func addImagesToView(images: [UIImage], view: UIView){
private func addImagesToView(images: [UIImage], view: UIView) {

self.thumbnailViews.removeAll()
var xPos: CGFloat = 0.0
var width: CGFloat = 0.0
for image in images{
for image in images {
DispatchQueue.main.async {
if xPos + view.frame.size.height < view.frame.width{
if xPos + view.frame.size.height < view.frame.width {
width = view.frame.size.height
}else{
} else {
width = view.frame.size.width - xPos
}

let imageView = UIImageView(image: image)
imageView.alpha = 0
imageView.contentMode = UIViewContentMode.scaleAspectFill
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.frame = CGRect(x: xPos,
y: 0.0,
width: width,
height: view.frame.size.height)
self.thumbnailViews.append(imageView)



view.addSubview(imageView)
UIView.animate(withDuration: 0.2, animations: {() -> Void in
imageView.alpha = 1.0
})
view.sendSubview(toBack: imageView)
view.sendSubviewToBack(imageView)
xPos = xPos + view.frame.size.height
}
}
}

private func thumbnailCount(inView: UIView) -> Int {
var num : Double = 0;

var num: Double = 0

DispatchQueue.main.sync {
num = Double(inView.frame.size.width) / Double(inView.frame.size.height)
}

return Int(ceil(num))
}
func updateThumbnails(view: UIView, videoURL: URL, duration: Float64) -> [UIImageView]{

func updateThumbnails(view: UIView, videoURL: URL, duration: Float64) -> [UIImageView] {

var thumbnails = [UIImage]()
var offset: Float64 = 0


for view in self.thumbnailViews{
DispatchQueue.main.sync
{
for view in self.thumbnailViews {
DispatchQueue.main.sync {
view.removeFromSuperview()
}
}

let imagesCount = self.thumbnailCount(inView: view)
for i in 0..<imagesCount{

for i in 0..<imagesCount {
let thumbnail = ABVideoHelper.thumbnailFromVideo(videoUrl: videoURL,
time: CMTimeMake(Int64(offset), 1))
time: CMTimeMake(value: Int64(offset), timescale: 1))
offset = Float64(i) * (duration / Float64(imagesCount))
thumbnails.append(thumbnail)
}
Expand Down
29 changes: 15 additions & 14 deletions ABVideoRangeSlider/Classes/ABTimeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,53 @@ import UIKit
open class ABTimeView: UIView {

let space: CGFloat = 8.0

public var timeLabel = UILabel()
public var backgroundView = UIView() {
willSet(newBackgroundView){
willSet(newBackgroundView) {
self.backgroundView.removeFromSuperview()
}
didSet {
self.frame = CGRect(x: 0,
y: -backgroundView.frame.height - space,
width: backgroundView.frame.width,
height: backgroundView.frame.height)

self.addSubview(backgroundView)
self.sendSubview(toBack: backgroundView)
self.sendSubviewToBack(backgroundView)
}
}

public var marginTop: CGFloat = 5.0
public var marginBottom: CGFloat = 5.0
public var marginLeft: CGFloat = 5.0
public var marginRight: CGFloat = 5.0

override init(frame: CGRect) {
super.init(frame: frame)
}
public init(size: CGSize, position: Int){

public init(size: CGSize, position: Int) {
let frame = CGRect(x: 0,
y: -size.height - space,
width: size.width,
height: size.height)
super.init(frame: frame)

// Add Background View
self.backgroundView.frame = self.bounds
self.backgroundView.backgroundColor = UIColor.yellow
self.backgroundView.backgroundColor = .yellow
self.backgroundView.layer.cornerRadius = 3.0
self.addSubview(self.backgroundView)

// Add time label
self.timeLabel = UILabel()
self.timeLabel.textAlignment = .center
self.timeLabel.textColor = UIColor.lightGray
self.timeLabel.textColor = .lightGray
self.addSubview(self.timeLabel)

}

open override func layoutSubviews() {
super.layoutSubviews()
self.backgroundView.frame = self.bounds
Expand All @@ -67,7 +68,7 @@ open class ABTimeView: UIView {
width: timeLabelFrameWidth,
height: timeLabelFrameHeight)
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
14 changes: 7 additions & 7 deletions ABVideoRangeSlider/Classes/ABVideoHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import AVFoundation

class ABVideoHelper: NSObject {

static func thumbnailFromVideo(videoUrl: URL, time: CMTime) -> UIImage{
static func thumbnailFromVideo(videoUrl: URL, time: CMTime) -> UIImage {
let asset: AVAsset = AVAsset(url: videoUrl) as AVAsset
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
do{
do {
let cgImage = try imgGenerator.copyCGImage(at: time, actualTime: nil)
let uiImage = UIImage(cgImage: cgImage)
return uiImage
}catch{
} catch {

}
return UIImage()
}
static func videoDuration(videoURL: URL) -> Float64{

static func videoDuration(videoURL: URL) -> Float64 {
let source = AVURLAsset(url: videoURL)
return CMTimeGetSeconds(source.duration)
}

}
Loading