BFVideoThumbProgressView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // BFVideoThumbProgressView.swift
  3. // BFRecordScreenKit
  4. //
  5. // Created by 胡志强 on 2021/12/3.
  6. //
  7. import Foundation
  8. import UIKit
  9. import AVFoundation
  10. import BFCommonKit
  11. import SnapKit
  12. class BFVideoThumbProgressView: UIView {
  13. var videoAsset : AVURLAsset?
  14. var thumbImgs = [UIImage]()
  15. init(frame: CGRect, videoAsset:AVURLAsset) {
  16. super.init(frame: frame)
  17. self.videoAsset = videoAsset
  18. addSubview(progressView)
  19. splitVideoFileUrlFps(urlAsset: videoAsset, fps: 2) {[weak self] isSuccess, images in
  20. if isSuccess{
  21. self?.thumbImgs = images!
  22. DispatchQueue.main.async {[weak self] in
  23. if let sself = self{
  24. for (i, img) in images!.enumerated() {
  25. let iv = UIImageView(image: img)
  26. iv.contentMode = .scaleAspectFill
  27. sself.progressView.addSubview(iv)
  28. iv.snp.makeConstraints { make in
  29. make.left.equalTo(CGFloat(i) * sself.height + sself.width * 0.5)
  30. make.top.height.equalToSuperview()
  31. make.width.equalTo(sself.height)
  32. }
  33. }
  34. sself.progressView.contentSize = CGSize(width: CGFloat(images!.count) * sself.height + sself.width, height: sself.height)
  35. }
  36. }
  37. }
  38. }
  39. }
  40. required init?(coder: NSCoder) {
  41. fatalError("init(coder:) has not been implemented")
  42. }
  43. lazy var progressView : UIScrollView = {
  44. let sv = UIScrollView()
  45. sv.bounces = false
  46. sv.backgroundColor = .clear
  47. sv.decelerationRate = .fast
  48. sv.showsHorizontalScrollIndicator = false
  49. return sv
  50. }()
  51. override func didMoveToWindow() {
  52. super.didMoveToWindow()
  53. }
  54. override func layoutSubviews() {
  55. super.layoutSubviews()
  56. progressView.snp.makeConstraints { make in
  57. make.edges.equalToSuperview()
  58. }
  59. }
  60. }