|
@@ -13,48 +13,12 @@ import SnapKit
|
|
|
import UIKit
|
|
|
|
|
|
class BFVideoThumbProgressView: UIView {
|
|
|
- var videoAsset: AVURLAsset? {
|
|
|
+ var recordItem: BFRecordItemModel? {
|
|
|
didSet {
|
|
|
- if let videoAsset = videoAsset {
|
|
|
- let dur = videoAsset.duration.seconds
|
|
|
- if dur > 0 {
|
|
|
- let fps = Double(fetchThumbStrategy.frameNumberOfVideo(assetDuration: dur)) / dur
|
|
|
-
|
|
|
- splitVideoFileUrlFps(urlAsset: videoAsset, fps: fps) { [weak self] images in
|
|
|
- if images.count > 0 {
|
|
|
- self?.thumbImgs = images
|
|
|
- DispatchQueue.main.async { [weak self] in
|
|
|
- if let sself = self {
|
|
|
- var lastiv = UIImageView()
|
|
|
- for (i, img) in images.enumerated() {
|
|
|
- let iv = UIImageView(image: img)
|
|
|
- iv.contentMode = .scaleAspectFill
|
|
|
- iv.clipsToBounds = true
|
|
|
- sself.progressView.contentView.addSubview(iv)
|
|
|
- iv.snp.makeConstraints { make in
|
|
|
- make.left.equalTo(CGFloat(i) * CGFloat(sself.thumbImageWidth) + sself.width * 0.5)
|
|
|
- make.top.bottom.equalToSuperview()
|
|
|
- make.height.equalTo(50)
|
|
|
- make.width.equalTo(sself.thumbImageWidth)
|
|
|
- }
|
|
|
- lastiv = iv
|
|
|
- }
|
|
|
- lastiv.snp.makeConstraints { make in
|
|
|
- make.right.equalTo(sself.width * -0.5)
|
|
|
- }
|
|
|
-
|
|
|
- sself.progressView.contentView.addSubview(sself.progessIndicateBackV)
|
|
|
- sself.progessIndicateBackV.snp.makeConstraints { make in
|
|
|
- make.left.equalTo(sself.width * 0.5)
|
|
|
- make.right.equalTo(sself.width * -0.5)
|
|
|
- make.bottom.equalToSuperview()
|
|
|
- make.height.equalTo(6)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if recordItem?.mediaType == .VIDEO {
|
|
|
+ dealWithVideoThub()
|
|
|
+ } else if recordItem?.mediaType == .IMAGE {
|
|
|
+ dealWithImageThub()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -70,7 +34,7 @@ class BFVideoThumbProgressView: UIView {
|
|
|
|
|
|
var progress: Double = 0 {
|
|
|
didSet {
|
|
|
- if let second = videoAsset?.duration.seconds, second > 0 {
|
|
|
+ if let second = recordItem?.videoAsset?.duration.seconds, second > 0 {
|
|
|
let w = progressView.contentSize.width - width
|
|
|
progressView.contentOffset = CGPoint(x: progress * Double(w) / second, y: 0)
|
|
|
}
|
|
@@ -82,11 +46,12 @@ class BFVideoThumbProgressView: UIView {
|
|
|
lazy var progressView: BFAutolayoutScrollView = {
|
|
|
let sv = BFAutolayoutScrollView()
|
|
|
sv.bounces = false
|
|
|
- sv.backgroundColor = .clear
|
|
|
+// sv.backgroundColor = .clear
|
|
|
+// sv.backgroundColor = UIColor.hexColor(hexadecimal: "#888888",alpha:0.3)
|
|
|
+ sv.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
|
|
|
sv.decelerationRate = .fast
|
|
|
sv.showsHorizontalScrollIndicator = false
|
|
|
sv.delegate = self
|
|
|
-
|
|
|
return sv
|
|
|
}()
|
|
|
|
|
@@ -124,6 +89,64 @@ class BFVideoThumbProgressView: UIView {
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ func dealWithVideoThub() {
|
|
|
+ guard let videoAsset = recordItem?.videoAsset else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let dur = videoAsset.duration.seconds
|
|
|
+ if dur > 0 {
|
|
|
+ let fps = Double(fetchThumbStrategy.frameNumberOfVideo(assetDuration: dur)) / dur
|
|
|
+ splitVideoFileUrlFps(urlAsset: videoAsset, fps: fps) { [weak self] images in
|
|
|
+ self?.addThubImages(images: images)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func dealWithImageThub() {
|
|
|
+ guard let image = recordItem?.coverImg else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ addThubImages(images: Array(repeating: image, count: 3))
|
|
|
+ }
|
|
|
+
|
|
|
+ func addThubImages(images: [UIImage]) {
|
|
|
+ if images.count > 0 {
|
|
|
+ thumbImgs = images
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
+ self?.progressView.contentView.subviews.forEach { subview in
|
|
|
+ subview.removeFromSuperview()
|
|
|
+ }
|
|
|
+ if let sself = self {
|
|
|
+ var lastiv = UIImageView()
|
|
|
+ for (i, img) in images.enumerated() {
|
|
|
+ let iv = UIImageView(image: img)
|
|
|
+ iv.contentMode = .scaleAspectFill
|
|
|
+ iv.clipsToBounds = true
|
|
|
+ sself.progressView.contentView.addSubview(iv)
|
|
|
+ iv.snp.makeConstraints { make in
|
|
|
+ make.left.equalTo(CGFloat(i) * CGFloat(sself.thumbImageWidth) + sself.width * 0.5)
|
|
|
+ make.top.bottom.equalToSuperview()
|
|
|
+ make.height.equalTo(50)
|
|
|
+ make.width.equalTo(sself.thumbImageWidth)
|
|
|
+ }
|
|
|
+ lastiv = iv
|
|
|
+ }
|
|
|
+ lastiv.snp.makeConstraints { make in
|
|
|
+ make.right.equalTo(sself.width * -0.5)
|
|
|
+ }
|
|
|
+
|
|
|
+ sself.progressView.contentView.addSubview(sself.progessIndicateBackV)
|
|
|
+ sself.progessIndicateBackV.snp.makeConstraints { make in
|
|
|
+ make.left.equalTo(sself.width * 0.5)
|
|
|
+ make.right.equalTo(sself.width * -0.5)
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
+ make.height.equalTo(6)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension BFVideoThumbProgressView: UIScrollViewDelegate {
|