PQStuckPointEditerController.swift 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. //
  2. // PQStuckPointEditerController.swift
  3. // PQSpeed
  4. //
  5. // Created by ak on 2021/4/26.
  6. // Copyright © 2021 BytesFlow. All rights reserved.
  7. // 功能:卡点音乐编辑界面
  8. import Foundation
  9. import ObjectMapper
  10. import RealmSwift
  11. import UIKit
  12. class PQStuckPointEditerController: PQBaseViewController {
  13. // 是否导出视频成功
  14. var isExportVideosSuccess: Bool = false
  15. // 是否请求卡点数据成功
  16. var isStuckPointDataSuccess: Bool = false
  17. // 是否同步音乐成功
  18. var isSynchroMusicInfoSuccess: Bool = false
  19. /// 当前所有的filter
  20. var filters: Array = Array<ImageProcessingOperation>.init()
  21. // 选中的总时长
  22. var selectedTotalDuration: Float64 = 0
  23. // 选择的总数
  24. var selectedDataCount: Int = 0
  25. // 选择的图片总数
  26. var selectedImageDataCount: Int = 0
  27. // 选中的素材数据
  28. var selectedPhotoData: [PQEditVisionTrackMaterialsModel]?
  29. // 选中的音乐数据
  30. var stuckPointMusicData: PQVoiceModel?
  31. // 保存所有段的所有贴纸,音频信息,用于播放器的渲染使用
  32. var projectModel: PQEditProjectModel = PQEditProjectModel()
  33. // 从草稿箱进入的项目数据
  34. var draftProjectModel: PQEditProjectModel?
  35. var mStickers: [PQEditVisionTrackMaterialsModel]?
  36. // 播放器的开始和结束时间,1,刚进界面使用推荐的开始结束时间,2,用户修改起结点时修改
  37. var playeTimeRange: CMTimeRange = CMTimeRange()
  38. // 下一步
  39. lazy var nextBtn: UIButton = {
  40. let nextBtn = UIButton(type: .custom)
  41. nextBtn.frame = CGRect(x: cScreenWidth - 16 - cDefaultMargin * 6, y: cDevice_iPhoneStatusBarHei + (cDevice_iPhoneNavBarHei - cDefaultMargin * 3) / 2, width: cDefaultMargin * 6, height: cDefaultMargin * 3)
  42. nextBtn.setTitle("合成", for: .normal)
  43. nextBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium)
  44. nextBtn.addTarget(self, action: #selector(nextBtnClick(sender:)), for: .touchUpInside)
  45. nextBtn.backgroundColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
  46. nextBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#FFFFFF"), for: .normal)
  47. nextBtn.uxy_acceptEventInterval = 0.5
  48. nextBtn.addCorner(corner: 3)
  49. return nextBtn
  50. }()
  51. // 播放器显示 view
  52. lazy var playerView: PQGPUImagePlayerView = {
  53. let playerHeight = cScreenWidth
  54. let playerView = PQGPUImagePlayerView(frame: CGRect(x: 0, y: navHeadImageView?.frame.maxY ?? 0, width: playerHeight, height: playerHeight))
  55. playerView.backgroundColor = PQBFConfig.shared.styleBackGroundColor
  56. playerView.isShowLine = false
  57. playerView.showGaussianBlur = true
  58. playerView.playerEmptyView.isHidden = true
  59. return playerView
  60. }()
  61. /// 节奏选择视图
  62. lazy var sustomSwitchView: PQCustomSwitchView = {
  63. let sustomSwitchView = PQCustomSwitchView(frame: CGRect(x: (view.frame.width - cDefaultMargin * 28) / 2, y: view.frame.height - cSafeAreaHeight - cDefaultMargin * 3 - cDefaultMargin * 3, width: cDefaultMargin * 28, height: 35), titles: ["快节奏", "适中", "慢节奏"], defaultIndex: stuckPointMusicData?.speed ?? 2)
  64. sustomSwitchView.switchChangeHandle = { [weak self] sender in
  65. // 改变速率
  66. self?.stuckPointMusicData?.speed = sender.tag
  67. self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.bgmInfo?.rhythmMusicSpeed = sender.tag
  68. // 播放前先暂停
  69. // self?.playerView.stop()
  70. // 开始播放
  71. self?.settingPlayerView()
  72. // 点击上报:选择节奏
  73. PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_selectRhythm, pageSource: .sp_stuck_previewSyncedUp, extParams: ["rhythmNumber": sender.tag], remindmsg: "点击上报:选择节奏")
  74. }
  75. return sustomSwitchView
  76. }()
  77. /// 裁剪视图
  78. lazy var stuckPointCuttingView: PQStuckPointCuttingView = {
  79. let stuckPointCuttingView = PQStuckPointCuttingView(frame: CGRect(x: 0, y: sustomSwitchView.frame.minY - cDefaultMargin * 14 - cDefaultMargin * 2, width: view.frame.width, height: cDefaultMargin * 14), duration: CGFloat(Float(stuckPointMusicData?.duration ?? "0") ?? 0), startTime: CGFloat(stuckPointMusicData?.startTime ?? 0), endTime: CGFloat(stuckPointMusicData?.endTime ?? 0))
  80. /// 裁剪进度回调
  81. stuckPointCuttingView.videoRangeDidChanged = { [weak self] startTime, endTime in
  82. BFLog(message: "裁剪返回--startTime = \(startTime),endTime = \(endTime)")
  83. }
  84. /// 播放进度回调
  85. stuckPointCuttingView.videoProgressDidChanged = { [weak self] progress in
  86. BFLog(message: "进度更新返回--progress = \(progress) \(String(describing: self?.playerView.mPlayeTimeRange))")
  87. }
  88. /// 拖缀结束的回调 type - 1-拖动左边裁剪结束 2--拖动右边裁剪结束 3-进度条拖动结束 4-滑动结束
  89. stuckPointCuttingView.videoDidEndDragging = { [weak self] type, startTime, endTime, progress in
  90. BFLog(message: "拖拽结束返回--type = \(type),startTime = \(startTime),endTime = \(endTime),progress = \(progress)")
  91. self?.playerView.pause()
  92. // 修改最新值
  93. self?.stuckPointMusicData?.startTime = Float64(startTime)
  94. self?.stuckPointMusicData?.endTime = Float64(endTime)
  95. // 红的指针完成
  96. if type == 3 {
  97. if CMTimeGetSeconds(self?.playerView.mPlayeTimeRange?.end ?? .zero) == 0 {
  98. BFLog(message: "mPlayeTimeRange is error")
  99. return
  100. }
  101. let newBeginSconds = (Double(startTime) + (Double(endTime) - Double(startTime)) * Double(progress)) * 600
  102. BFLog(message: " newBeginSconds is \(newBeginSconds)")
  103. let seekTimeRange: CMTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue(Int64(newBeginSconds)), timescale: 600), end:
  104. CMTime(value: CMTimeValue(Int64(endTime * 600)), timescale: 600))
  105. BFLog(message: "修改的开始 \(CMTimeGetSeconds(seekTimeRange.start)) 结束 \(CMTimeGetSeconds(seekTimeRange.end))")
  106. //重新设置有效缓存
  107. self?.playerView.configCache(beginTime: CMTimeGetSeconds(seekTimeRange.start))
  108. self?.playerView.play(pauseFirstFrame: false, playeTimeRange: seekTimeRange)
  109. } else {
  110. // 更改素材开始时间及结束时间
  111. self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.out = Float64(endTime)
  112. self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.model_in = Float64(startTime)
  113. self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.timelineIn = Float64(startTime)
  114. self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.timelineOut = Float64(endTime)
  115. BFLog(message: "调整后总时长: \(endTime - startTime) startTime:\(startTime) endTime:\(endTime)")
  116. // 初始化音频的开始和结束时间
  117. self?.playeTimeRange = CMTimeRange(start: CMTimeMakeWithSeconds(Float64(startTime), preferredTimescale: BASE_FILTER_TIMESCALE), end: CMTimeMakeWithSeconds(Float64(endTime), preferredTimescale: BASE_FILTER_TIMESCALE))
  118. DispatchQueue.global().async { // 并行、异步
  119. let beginTime: TimeInterval = Date().timeIntervalSince1970
  120. self?.mStickers = self?.createStickers(sections: self?.projectModel.sData?.sections ?? List(), inputSize: CGSize(width: CGFloat(self?.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self?.projectModel.sData?.videoMetaData?.videoHeight ?? 0)))
  121. self?.playerView.mStickers = self?.mStickers
  122. DispatchQueue.main.async { // 串行、异步
  123. var endTime: TimeInterval = Date().timeIntervalSince1970
  124. BFLog(message: "endTime is endTimeendTime \(endTime = beginTime)")
  125. self?.playerView.play(pauseFirstFrame: false, playeTimeRange: self!.playeTimeRange)
  126. }
  127. }
  128. }
  129. // 埋点上报
  130. if type == 1 || type == 2 {
  131. // 点击上报:拖动拖拽条(左/右部分)
  132. PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: type == 1 ? .ot_click_dragFront : .ot_click_dragBehind, pageSource: .sp_stuck_previewSyncedUp, extParams: ["targetTime": type == 1 ? startTime * 1000 : endTime * 1000], remindmsg: "点击上报:拖动拖拽条(左/右部分)")
  133. }
  134. }
  135. return stuckPointCuttingView
  136. }()
  137. /// 卡点时长显示视图
  138. lazy var timeRemindLab: UILabel = {
  139. let timeRemindLab = UILabel(frame: CGRect(x: 0, y: stuckPointCuttingView.frame.minY - cDefaultMargin * 4 - cDefaultMargin * 3, width: view.frame.width, height: cDefaultMargin * 4))
  140. timeRemindLab.backgroundColor = UIColor.hexColor(hexadecimal: "#262626")
  141. timeRemindLab.textAlignment = .center
  142. timeRemindLab.font = UIFont.systemFont(ofSize: 12)
  143. timeRemindLab.textColor = UIColor.hexColor(hexadecimal: "#999999")
  144. let total: Float64 = ((stuckPointMusicData?.endTime ?? Float64(stuckPointMusicData?.duration ?? "0") ?? 0) - (stuckPointMusicData?.startTime ?? 0))
  145. timeRemindLab.text = "现卡点时长\(total.formatDurationToHMS()) / 原视频总时长\(selectedTotalDuration.formatDurationToHMS())"
  146. return timeRemindLab
  147. }()
  148. /// 音乐标题
  149. lazy var musicNameView: UIView = {
  150. let musicNameView = UIView()
  151. musicNameView.addSubview(musicNameLab)
  152. let nameWidth: CGFloat = musicNameLab.frame.width + (25 + cDefaultMargin * 3)
  153. musicNameView.frame = CGRect(x: (view.frame.width - nameWidth) / 2, y: cDevice_iPhoneStatusBarHei + (cDevice_iPhoneNavBarHei - cDefaultMargin * 3) / 2, width: nameWidth, height: cDefaultMargin * 3)
  154. // musicNameView.backgroundColor = UIColor.hexColor(hexadecimal: "#333333")
  155. musicNameView.addCorner(corner: musicNameView.frame.height / 2)
  156. let musicImageView = UIImageView()
  157. musicImageView.tintColor = PQBFConfig.shared.styleTitleColor
  158. musicImageView.image = UIImage().BF_Image(named: "stuckPoint_reCreate_music").withRenderingMode(.alwaysTemplate)
  159. musicImageView.frame = CGRect(x: musicNameView.frame.height / 2 - 5, y: (musicNameView.frame.height - 22) / 2, width: 22, height: 22)
  160. musicNameView.addSubview(musicImageView)
  161. musicNameLab.frame.origin.x = musicImageView.frame.maxX + 5
  162. let ges = UITapGestureRecognizer(target: self, action: #selector(musicNameClick))
  163. musicNameView.addGestureRecognizer(ges)
  164. return musicNameView
  165. }()
  166. /// 音乐歌曲名称
  167. lazy var musicNameLab: LMJHorizontalScrollText = {
  168. let nameWidth: CGFloat = sizeWithText(text: "\(stuckPointMusicData?.musicName ?? "")", font: UIFont.systemFont(ofSize: 13), size: CGSize(width: view.frame.width - ((cDefaultMargin * 6 + 16 * 2) * 2) - (25 + cDefaultMargin * 3), height: cDefaultMargin * 3)).width
  169. let musicNameLab = LMJHorizontalScrollText(frame: CGRect(x: 0, y: 0, width: nameWidth < cDefaultMargin * 4 ? cDefaultMargin * 4 : nameWidth, height: cDefaultMargin * 3))
  170. musicNameLab.textColor = PQBFConfig.shared.styleTitleColor
  171. musicNameLab.textFont = UIFont.systemFont(ofSize: 13)
  172. musicNameLab.speed = 0.03
  173. musicNameLab.moveDirection = LMJTextScrollMoveLeft
  174. musicNameLab.moveMode = LMJTextScrollContinuous
  175. if nameWidth < cDefaultMargin * 4 {
  176. musicNameLab.text = " \(stuckPointMusicData?.musicName ?? "") "
  177. } else {
  178. musicNameLab.text = " \(stuckPointMusicData?.musicName ?? "") "
  179. }
  180. return musicNameLab
  181. }()
  182. /// 同步进度显示
  183. lazy var synchroMarskView: PQStuckPointLoadingView = {
  184. var synchroMarskView = PQStuckPointLoadingView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
  185. synchroMarskView.cancelHandle = { [weak self] _ in
  186. self?.navigationController?.popViewController(animated: true)
  187. }
  188. return synchroMarskView
  189. }()
  190. override func viewWillAppear(_ animated: Bool) {
  191. super.viewDidAppear(animated)
  192. lineView?.isHidden = true
  193. UIApplication.shared.isIdleTimerDisabled = true
  194. musicNameLab.move()
  195. PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
  196. }
  197. @objc func enterBackground() {
  198. BFLog(message: "进入到后台")
  199. // 取消导出
  200. playerView.pause()
  201. }
  202. override func backBtnClick() {
  203. super.backBtnClick()
  204. playerView.pause()
  205. // 点击上报:返回按钮
  206. PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_back, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "卡点视频数据上报-(点击上报:返回按钮)")
  207. }
  208. @objc func musicNameClick() {
  209. // let musicVc = navigationController?.viewControllers.first(where: { vc in
  210. // vc is PQStuckPointMusicController
  211. // })
  212. // if musicVc != nil {
  213. // navigationController?.popToViewController(musicVc!, animated: true)
  214. // }
  215. }
  216. override func viewWillDisappear(_ animated: Bool) {
  217. super.viewWillDisappear(animated)
  218. UIApplication.shared.isIdleTimerDisabled = false
  219. musicNameLab.stop()
  220. playerView.pause()
  221. }
  222. override func viewDidLoad() {
  223. super.viewDidLoad()
  224. leftButton(image: "icon_detail_back", tintColor: PQBFConfig.shared.styleTitleColor)
  225. navHeadImageView?.addSubview(nextBtn)
  226. navHeadImageView?.addSubview(musicNameView)
  227. // 添加子视图
  228. addSubViews()
  229. // 导出相册视频
  230. exportPhotoData()
  231. // 同步音乐数据
  232. synchroMusicInfoData()
  233. // 曝光上报:预览页面曝光上报
  234. PQEventTrackViewModel.baseReportUpload(businessType: .bt_windowView, objectType: .ot_view_previewSyncedUp, pageSource: .sp_stuck_previewSyncedUp, extParams: nil, remindmsg: "卡点视频数据上报-(曝光上报:预览页面曝光上报)")
  235. }
  236. /// 添加子视图
  237. /// - Returns: <#description#>
  238. func addSubViews() {
  239. if (stuckPointMusicData?.rhythmSdata.count ?? 0) <= 0 {
  240. return
  241. }
  242. view.addSubview(playerView)
  243. view.addSubview(sustomSwitchView)
  244. view.addSubview(stuckPointCuttingView)
  245. // view.addSubview(timeRemindLab)
  246. // 添加一个背景区分不同色值
  247. let backView: UIView = UIView()
  248. backView.backgroundColor = PQBFConfig.shared.styleBackGroundColor
  249. view.insertSubview(backView, aboveSubview: navHeadImageView!)
  250. backView.frame = CGRect(x: 0, y: navHeadImageView?.frame.height ?? 0, width: cScreenWidth, height: (stuckPointCuttingView.frame.minY - cDefaultMargin * 3) - (navHeadImageView?.frame.height ?? 0))
  251. }
  252. @objc func nextBtnClick(sender _: UIButton) {
  253. BFLog(message: "去发布")
  254. playerView.pause()
  255. let videoExporter = PQStuckPointPublicController()
  256. videoExporter.selectedTotalDuration = selectedTotalDuration
  257. videoExporter.selectedDataCount = selectedDataCount
  258. videoExporter.selectedImageDataCount = selectedImageDataCount
  259. // 使用深 copy
  260. let json = projectModel.toJSONString(prettyPrint: false)
  261. if json == nil {
  262. BFLog(message: "数据转换有问题 跳转")
  263. return
  264. }
  265. let tempModel: PQEditProjectModel? = Mapper<PQEditProjectModel>().map(JSONString: json!)
  266. videoExporter.mStickers = mStickers
  267. videoExporter.audioMixModel = stuckPointMusicData
  268. videoExporter.editProjectModel = tempModel
  269. navigationController?.pushViewController(videoExporter, animated: true)
  270. // 点击上报:去合成
  271. PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_commit, pageSource: .sp_stuck_previewSyncedUp, extParams: ["musicName": stuckPointMusicData?.musicName ?? "", "musicId": stuckPointMusicData?.musicId ?? "", "rhythmNumber": stuckPointMusicData?.speed ?? 2, "duration": ((stuckPointMusicData?.endTime ?? 0) - (stuckPointMusicData?.startTime ?? 0)) * 1000], remindmsg: "点击上报:去合成")
  272. }
  273. // MARK: - 播放器相关操作
  274. /// seek 播放器
  275. /// - Parameter playeTimeRange: 开始和结束时间
  276. func seekPlayer(playeTimeRange: CMTimeRange) {
  277. playerView.setEnableSeek(isSeek: true)
  278. playerView.play(pauseFirstFrame: false, playeTimeRange: playeTimeRange)
  279. }
  280. /// 通过传入的 selectedPhotoData 、 stuckPointMusicData 创建 projectModel 模型 后面都使用 projectModel 参数
  281. func createPorjectData() {
  282. // 1,添加选择的视觉素材
  283. let section: PQEditSectionModel = PQEditSectionModel()
  284. selectedPhotoData?.forEach { model in
  285. let json = model.toJSONString(prettyPrint: false)
  286. if json == nil {
  287. BFLog(message: "数据转换有问题 跳转")
  288. return
  289. }
  290. let tempModel: PQEditVisionTrackMaterialsModel = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: json!)!
  291. section.sectionTimeline?.visionTrack?.visionTrackMaterials.append(tempModel)
  292. }
  293. projectModel.sData?.sections.append(section)
  294. // 2,添加背景音乐
  295. projectModel.sData?.addBGM(audioMix: stuckPointMusicData!)
  296. }
  297. // 设置播放器
  298. func settingPlayerView() {
  299. // 1,设置播放器的显示区域 和画布大小
  300. // - 按第一个素材尺寸自适应
  301. let playerShowHeight = (stuckPointCuttingView.frame.minY - cDefaultMargin * 3) - (navHeadImageView?.frame.maxY ?? 0)
  302. var showRect: CGRect = PQPlayerViewModel.getShowCanvasRect(editProjectModel: projectModel, showType: 1, playerViewHeight: playerShowHeight)
  303. if showRect.size.width == showRect.size.height {
  304. if cScreenWidth > playerShowHeight {
  305. showRect.origin.x = (cScreenWidth - playerShowHeight) / 2
  306. showRect.size.width = playerShowHeight
  307. showRect.size.height = playerShowHeight
  308. } else {
  309. showRect.origin.x = 0
  310. showRect.size.width = cScreenWidth
  311. showRect.size.height = cScreenWidth
  312. }
  313. }
  314. showRect.origin.y = (playerShowHeight - showRect.size.height) / 2.0 + (navHeadImageView?.frame.maxY ?? 0)
  315. if showRect.size.width != 0, showRect.size.height != 0 {
  316. playerView.resetCanvasFrame(frame: showRect)
  317. }
  318. var firstModel: PQEditVisionTrackMaterialsModel?
  319. for part in projectModel.sData!.sections {
  320. if part.sectionTimeline?.visionTrack?.getEnableVisionTrackMaterials().count ?? 0 > 0 {
  321. firstModel = part.sectionTimeline?.visionTrack?.getEnableVisionTrackMaterials().first
  322. break
  323. }
  324. }
  325. var videoSize: CGSize = CGSize(width: Int(firstModel?.width ?? 0), height: Int(firstModel?.height ?? 0))
  326. var minSlider = min(videoSize.width, videoSize.height)
  327. var maxSlider = max(videoSize.width, videoSize.height)
  328. let ration = 1080 / minSlider
  329. minSlider = minSlider * ration
  330. maxSlider = maxSlider * ration
  331. if videoSize.width > videoSize.height { // 宽屏
  332. videoSize = CGSize(width: maxSlider, height: minSlider)
  333. } else {
  334. videoSize = CGSize(width: minSlider, height: maxSlider)
  335. }
  336. let maxValue = max(videoSize.width ?? 0, videoSize.height ?? 0)
  337. if maxValue > 1920 {
  338. let maxRation = 1920 / maxValue
  339. videoSize = CGSize(width: videoSize.width * CGFloat(maxRation), height: videoSize.height * CGFloat(maxRation))
  340. BFLog(message: "最长边已经超过 1920 要等比缩小 缩放后\(videoSize)")
  341. }
  342. if (Int(videoSize.width) % 2) != 0 {
  343. videoSize.width = videoSize.width - 1
  344. }
  345. if (Int(videoSize.height) % 2) != 0 {
  346. videoSize.height = videoSize.height - 1
  347. }
  348. projectModel.sData?.videoMetaData?.videoWidth = Int(videoSize.width)
  349. projectModel.sData?.videoMetaData?.videoHeight = Int(videoSize.height)
  350. // 2,创建滤镜
  351. let beginTime: TimeInterval = Date().timeIntervalSince1970
  352. self.mStickers = self.createStickers(sections: self.projectModel.sData?.sections ?? List(), inputSize: CGSize(width: CGFloat(self.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self.projectModel.sData?.videoMetaData?.videoHeight ?? 0)))
  353. self.playerView.mStickers = self.mStickers
  354. let end: TimeInterval = Date().timeIntervalSince1970
  355. BFLog(message: "createStickers tiskskskskme \(end - beginTime)")
  356. // 3,设置音频
  357. let audioPath = self.stuckPointMusicData?.localPath ?? ""
  358. BFLog(message: "初始化音频播放器的音频地址为:\(audioPath)")
  359. self.playerView.stop()
  360. // 这里的测试这个音乐播放有问题
  361. // self.playerView.updateAsset(URL(fileURLWithPath: "63930549652d74e477141e3b79c8d29a9ef8af81625053214516.mp3", relativeTo:Bundle.main.resourceURL!), videoComposition: nil, audioMixModel: nil)
  362. self.playerView.updateAsset(URL(fileURLWithPath: documensDirectory + audioPath), videoComposition: nil, audioMixModel: nil)
  363. let end2: TimeInterval = Date().timeIntervalSince1970
  364. BFLog(message: "updateAsset tiskskskskme \(end2 - end)")
  365. // 4, 设置播放器的输出画布大小
  366. self.playerView.movie?.mShowVidoSize = CGSize(width: CGFloat(self.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self.projectModel.sData?.videoMetaData?.videoHeight ?? 0))
  367. // 5,开始播放
  368. self.playerView.isLoop = false
  369. self.playerView.showProgressLab = true
  370. // 初始化音频的开始和结束时间
  371. BFLog(message: "播放的器 开始\(String(describing: CMTimeGetSeconds(self.playeTimeRange.start))) 结束 \(String(describing: CMTimeGetSeconds(self.playeTimeRange.end)))")
  372. let end3: TimeInterval = Date().timeIntervalSince1970
  373. self.playerView.play(pauseFirstFrame: false, playeTimeRange: CMTimeRange(start: self.playeTimeRange.start, end: self.playeTimeRange.end))
  374. let end4: TimeInterval = Date().timeIntervalSince1970
  375. BFLog(message: " playerView.play tiskskskskme \(end4 - end3)")
  376. // 6,进度回调
  377. self.playerView.progress = { [weak self] currentTime, tatolTime, _ in
  378. // 更新进度
  379. let progress = (currentTime - CMTimeGetSeconds(self?.playeTimeRange.start ?? .zero
  380. )) / CMTimeGetSeconds(self?.playeTimeRange.duration ?? .zero
  381. )
  382. BFLog(message: "\(currentTime) \(tatolTime) 显示播放器进度为: \(progress)")
  383. self?.stuckPointCuttingView.videoCropView.updateProgress(progress: CGFloat(progress))
  384. if self?.synchroMarskView.superview != nil {
  385. self?.synchroMarskView.removeMarskView()
  386. }
  387. }
  388. }
  389. deinit {
  390. BFLog(message: "卡点视频预览界面销毁")
  391. musicNameLab.stop()
  392. playerView.pause()
  393. // 取消所有的导出
  394. PQSingletoMemoryUtil.shared.allExportSession.forEach { _, exportSession in
  395. exportSession.cancelExport()
  396. }
  397. }
  398. }
  399. // MARK: - 视频渲染相关逻辑方法
  400. extension PQStuckPointEditerController {
  401. /// 分割视频 这里只设置视频类型的 in 和 out 并不设置显示的开始和结束时间 mp4 ,png ,png ,mp4
  402. /// - Parameter section: 当前段
  403. /// - Parameter stuckPoints: 用户选择的,或推荐的卡点数
  404. /// - Returns: 返回分割后的所有 stickers 和卡点数是一致的
  405. func clipVideoMerage(section: PQEditSectionModel, stuckPoints: [Float]) -> [PQEditVisionTrackMaterialsModel] {
  406. var stickers: Array = Array<PQEditVisionTrackMaterialsModel>.init()
  407. // 第二种情况:有视频要进行分割
  408. /*
  409. 1, 确定每个视频素材需要切的段数p
  410. 2, 将所有视频时长相加,得到总视频素材时长L = l1 + l2 + ... + ln
  411. 3, 视频素材a1需要切分的个数clipNum = max (round (kongduan * a1 / L) , 1)
  412. */
  413. // 要补的空位数
  414. let kongduan: Int = Int(stuckPoints.count) - Int(section.sectionTimeline!.visionTrack?.getEnableVisionTrackMaterials().count ?? 0)
  415. // 所有视频总时长
  416. var videoTotalDuration: Float64 = 0.0
  417. for video in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video") {
  418. let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + video.locationPath), options: nil)
  419. videoTotalDuration = videoTotalDuration + Float64(CMTimeGetSeconds(asset.duration))
  420. }
  421. if videoTotalDuration == 0 {
  422. BFLog(message: "视频总时长出现错误!!!!这里应该有视频素材的")
  423. return stickers
  424. }
  425. for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
  426. if sticker.type == StickerType.VIDEO.rawValue {
  427. let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
  428. // 要分割的段落
  429. let clipNum = Int(max(round(Double(kongduan) * CMTimeGetSeconds(asset.duration) / videoTotalDuration), 1))
  430. sticker.duration = CMTimeGetSeconds(asset.duration)
  431. BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(clipNum)")
  432. for clipindex in 0 ... clipNum - 1 {
  433. // deep copy sticker model 防止只有一个对象
  434. let stickerjson = sticker.toJSONString(prettyPrint: false)
  435. let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
  436. // 设置循环模式和适配模式
  437. deepCopySticker?.generateDefaultValues()
  438. deepCopySticker?.model_in = clipindex == 0 ? 0 : CMTimeGetSeconds(asset.duration) / Double(clipNum) * Double(clipindex)
  439. deepCopySticker?.out = (deepCopySticker?.model_in ?? 0) + CMTimeGetSeconds(asset.duration) / Double(clipNum)
  440. if (deepCopySticker?.model_in ?? 0) >= CMTimeGetSeconds(asset.duration) || (deepCopySticker?.out ?? 0) >= CMTimeGetSeconds(asset.duration) {
  441. deepCopySticker?.model_in = CMTimeGetSeconds(asset.duration) - CMTimeGetSeconds(asset.duration) / Double(clipNum)
  442. deepCopySticker?.out = CMTimeGetSeconds(asset.duration)
  443. }
  444. BFLog(message: " crilp is in \(deepCopySticker?.model_in ?? 0) out \(deepCopySticker?.out ?? 0) 总时长\(CMTimeGetSeconds(asset.duration))")
  445. if deepCopySticker != nil {
  446. stickers.append(deepCopySticker!)
  447. }
  448. }
  449. } else if sticker.type == StickerType.IMAGE.rawValue {
  450. sticker.generateDefaultValues()
  451. stickers.append(sticker)
  452. }
  453. }
  454. return stickers
  455. }
  456. /// 创建sticker
  457. /// - Parameters:
  458. /// - sections: 项目所有段落数据信息
  459. /// - inputSize: 画布大小
  460. /// - Returns: filters 数据 播放器可直接使用
  461. func createStickers(sections: List<PQEditSectionModel>, inputSize _: CGSize = .zero) -> [PQEditVisionTrackMaterialsModel] {
  462. // 保存滤镜对象数据
  463. var stickers: Array = Array<PQEditVisionTrackMaterialsModel>.init()
  464. for section in sections {
  465. if section.sectionType == "normal" {
  466. // 推荐卡点数
  467. var stuckPoints: Array = Array<Float>.init()
  468. var stuckPointsTemp = Array<Float>.init()
  469. for (index, dunshu) in stuckPointMusicData!.rhythmSdata[0].pointTimes.enumerated() {
  470. BFLog(message: "原所有卡点数:\(index) \(Float(dunshu) / Float(BASE_FILTER_TIMESCALE))")
  471. if Float64(dunshu) / Float64(BASE_FILTER_TIMESCALE) > CMTimeGetSeconds(playeTimeRange.start), Float64(dunshu) / Float64(BASE_FILTER_TIMESCALE) < CMTimeGetSeconds(playeTimeRange.end) {
  472. stuckPointsTemp.append(Float(dunshu) / Float(BASE_FILTER_TIMESCALE))
  473. }
  474. }
  475. // 根据不同速度 取卡点 1,2,3
  476. /*
  477. - 快节奏为选中区域的所有点位,即0,1,2,3,4……
  478. - 适中为每两个点位取一个,即0,2,4,6……
  479. - 慢节奏为每三个点位取一个,即0,3,6,9……
  480. */
  481. BFLog(message: "stuckPointMusicData?.speed is \(String(describing: stuckPointMusicData?.speed))")
  482. for (index, point) in stuckPointsTemp.enumerated() {
  483. if stuckPointMusicData?.speed == 1 {
  484. stuckPoints.append(Float(point))
  485. } else if stuckPointMusicData?.speed == 2 {
  486. if index % 2 == 0 {
  487. stuckPoints.append(point)
  488. }
  489. } else if stuckPointMusicData?.speed == 3 {
  490. if index % 3 == 0 {
  491. stuckPoints.append(point)
  492. }
  493. }
  494. }
  495. for point in stuckPoints {
  496. BFLog(message: "没有 start end 计算后的卡点数\(point)")
  497. }
  498. if stuckPoints.first != nil {
  499. stuckPoints.removeFirst()
  500. }
  501. if stuckPoints.last != nil {
  502. stuckPoints.removeLast()
  503. }
  504. //开始时间是服务器返回, 结果时间根据策略计算的
  505. stuckPoints.insert(Float(CMTimeGetSeconds(playeTimeRange.start)), at: 0)
  506. stuckPoints.insert((Float(CMTimeGetSeconds(playeTimeRange.end))), at: stuckPoints.count)
  507. for point in stuckPoints {
  508. BFLog(message: "有 start end 计算后的卡点数\(point)")
  509. }
  510. BFLog(message: "stuckPoints count is \(stuckPoints.count)")
  511. // 当用户上传视觉素材个数大于等于音乐选择区域节拍分割个数时,无需进行视频分割,只显示卡点数-1 个素材
  512. if section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().count >= stuckPointMusicData!.rhythmSdata[0].pointTimes.count {
  513. for (index, sticker) in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().enumerated() {
  514. if index == stuckPointMusicData!.rhythmSdata[0].pointTimes.count {
  515. BFLog(message: "到达卡点数量")
  516. break
  517. }
  518. BFLog(message: "创建 filter start :\(sticker.timelineIn) end :\(sticker.timelineOut) type is \(sticker.type) \(sticker.locationPath)")
  519. sticker.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
  520. sticker.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
  521. BFLog(message: "卡点 间隔 \(sticker.timelineIn - sticker.timelineOut)")
  522. sticker.generateDefaultValues()
  523. stickers.append(sticker)
  524. }
  525. } else {
  526. // 卡点数 > 选择素材数
  527. // 第一种情况:全是图片,图片回环播放
  528. if section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video").count == 0, section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "image").count > 0 {
  529. for (index, point) in stuckPoints.enumerated() {
  530. let sticker: PQEditVisionTrackMaterialsModel = section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials()[index % section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().count]
  531. BFLog(message: "stickerlocationPath sticker : \(sticker.locationPath)")
  532. let stickerjson = sticker.toJSONString(prettyPrint: false)
  533. let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
  534. if deepCopySticker!.type == StickerType.IMAGE.rawValue {
  535. if index + 1 < stuckPoints.count {
  536. deepCopySticker!.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
  537. deepCopySticker!.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
  538. if deepCopySticker != nil {
  539. deepCopySticker?.generateDefaultValues()
  540. stickers.append(deepCopySticker!)
  541. }
  542. }
  543. }
  544. }
  545. } else {
  546. // 第二种情况:有视频要进行分割
  547. let clipFilters = clipVideoMerage(section: section, stuckPoints: stuckPoints)
  548. for (index, point) in stuckPoints.enumerated() {
  549. BFLog(message: "aaaaaindexindeindexxindexindexindex \(index) \(point)")
  550. if index + 1 < stuckPoints.count, index < clipFilters.count {
  551. BFLog(message: "bbbbbindexindeindexxindexindexindex \(index) \(point)")
  552. let sticker: PQEditVisionTrackMaterialsModel = clipFilters[index]
  553. sticker.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
  554. // TODO 不是最好方案
  555. sticker.timelineOut = Float64("\(stuckPoints[index + 1] )") ?? 0.0
  556. // 卡点的时间 > in out 值 这里就会出现鬼畜效果
  557. let timelineInterval = sticker.timelineOut - sticker.timelineIn
  558. let inOutInterval = sticker.out - sticker.model_in
  559. if timelineInterval > inOutInterval {
  560. BFLog(message: "实际要显示卡点时长\(timelineInterval) 素材裁剪时长:\(inOutInterval)")
  561. sticker.out = sticker.model_in + timelineInterval
  562. //下面只是 LOG 方便查问题
  563. let stickerInOut = sticker.out - sticker.model_in
  564. let stickerTimelineInOut = sticker.timelineOut - sticker.timelineIn
  565. if(stickerInOut != stickerTimelineInOut){
  566. BFLog(message: "sticker.timelineIn \(sticker.timelineIn) stickerTimelineInOut is\(stickerTimelineInOut) stickerInOut is\(stickerInOut) 相差\(stickerTimelineInOut - stickerInOut)")
  567. }
  568. }
  569. // out > 素材的总时长in out 进行前移操作
  570. let offsetAssetDuration = sticker.out - sticker.duration
  571. if offsetAssetDuration > 0 {
  572. sticker.model_in = sticker.model_in - offsetAssetDuration
  573. sticker.out = sticker.out - offsetAssetDuration
  574. }
  575. BFLog(message: "index is \(index)分割后 创建 filter timelineIn :\(sticker.timelineIn) timelineOut :\(sticker.timelineOut) in :\(sticker.model_in) out:\(sticker.out) type is \(sticker.type) 显示总时长为:\(sticker.timelineOut - sticker.timelineIn) 裁剪总时长\(sticker.out - sticker.model_in)")
  576. stickers.append(sticker)
  577. }
  578. }
  579. }
  580. }
  581. }
  582. }
  583. return stickers
  584. }
  585. }
  586. // MARK: - 同步/下载素材相关
  587. /// 同步/下载素材相关
  588. extension PQStuckPointEditerController {
  589. /// 同步音乐相关数据
  590. /// - Returns: <#description#>
  591. func synchroMusicInfoData() {
  592. if (stuckPointMusicData?.rhythmSdata.count ?? 0) <= 0 {
  593. if synchroMarskView.superview == nil {
  594. UIApplication.shared.keyWindow?.addSubview(synchroMarskView)
  595. }
  596. PQStuckPointViewModel.stuckPointMusicDetailData(musicId: stuckPointMusicData?.musicId ?? "", originType: stuckPointMusicData?.originType ?? 1) { [weak self] newMusicData, _ in
  597. if newMusicData != nil, (newMusicData?.rhythmSdata.count ?? 0) > 0 {
  598. self?.isStuckPointDataSuccess = true
  599. self?.stuckPointMusicData?.rhythmSdata = newMusicData?.rhythmSdata ?? []
  600. self?.stuckPointMusicData?.startTime = newMusicData?.startTime ?? 0
  601. self?.stuckPointMusicData?.endTime = newMusicData?.endTime ?? 0
  602. if newMusicData?.speed != nil {
  603. self?.stuckPointMusicData?.speed = newMusicData?.speed ?? 2
  604. }
  605. if (self?.stuckPointMusicData?.rhythmSdata.count ?? 0) > 0 && (((self?.selectedDataCount ?? 0) - (self?.selectedImageDataCount ?? 0)) > 0 || (self?.selectedImageDataCount ?? 0) > 0 || (self?.selectedTotalDuration ?? 0) > 0) {
  606. self?.stuckPointMusicData?.endTime = (self?.stuckPointMusicData?.startTime ?? 0) + (self?.stuckPointMusicData?.stuckPointCuttingTime(videoCount: (self?.selectedDataCount ?? 0) - (self?.selectedImageDataCount ?? 0), imageCount: self?.selectedImageDataCount ?? 0, totalDuration: self?.selectedTotalDuration ?? 0) ?? 0)
  607. }
  608. self?.stuckPointCuttingView.updateEndTime(startTime: CGFloat(self?.stuckPointMusicData?.startTime ?? 0), endTime: CGFloat(self?.stuckPointMusicData?.endTime ?? 0))
  609. if self?.stuckPointMusicData?.localPath == nil || (self?.stuckPointMusicData?.localPath?.count ?? 0) > 0 {
  610. PQDownloadManager.downLoadFile(url: self?.stuckPointMusicData?.musicPath ?? "") { [weak self] filePath, error in
  611. if error == nil, filePath != nil {
  612. self?.isSynchroMusicInfoSuccess = true
  613. self?.stuckPointMusicData?.localPath = filePath?.replacingOccurrences(of: documensDirectory, with: "")
  614. // 处理所有数据完成
  615. self?.dealWithDataSuccess()
  616. } else {
  617. if self?.synchroMarskView.superview != nil {
  618. self?.synchroMarskView.removeMarskView()
  619. }
  620. // PQUploadRemindView.showUploadRemindView(title: nil, attributedTitle: NSAttributedString(string: "加载音乐失败,请重新选择音乐"), summary: "", confirmTitle: nil) { [weak self] _, _ in
  621. // self?.navigationController?.popViewController(animated: true)
  622. // }
  623. }
  624. }
  625. } else {
  626. self?.isSynchroMusicInfoSuccess = true
  627. // 处理所有数据完成
  628. self?.dealWithDataSuccess()
  629. }
  630. // 添加子视图
  631. self?.addSubViews()
  632. } else {
  633. if self?.synchroMarskView.superview != nil {
  634. self?.synchroMarskView.removeMarskView()
  635. }
  636. // PQUploadRemindView.showUploadRemindView(title: nil, attributedTitle: NSAttributedString(string: "加载音乐失败,请重新选择音乐"), summary: "", confirmTitle: nil) { [weak self] _, _ in
  637. // self?.navigationController?.popViewController(animated: true)
  638. // }
  639. }
  640. }
  641. } else if stuckPointMusicData?.localPath == nil || (stuckPointMusicData?.localPath?.count ?? 0) > 0 {
  642. if synchroMarskView.superview == nil {
  643. UIApplication.shared.keyWindow?.addSubview(synchroMarskView)
  644. }
  645. isStuckPointDataSuccess = true
  646. PQDownloadManager.downLoadFile(url: stuckPointMusicData?.musicPath ?? "") { [weak self] filePath, error in
  647. if error == nil, filePath != nil {
  648. self?.isSynchroMusicInfoSuccess = true
  649. self?.stuckPointMusicData?.localPath = filePath?.replacingOccurrences(of: documensDirectory, with: "")
  650. // 处理所有数据完成
  651. self?.dealWithDataSuccess()
  652. } else {
  653. if self?.synchroMarskView.superview != nil {
  654. self?.synchroMarskView.removeMarskView()
  655. }
  656. // PQUploadRemindView.showUploadRemindView(title: nil, attributedTitle: NSAttributedString(string: "加载音乐失败,请重新选择音乐"), summary: "", confirmTitle: nil) { [weak self] _, _ in
  657. // self?.navigationController?.popViewController(animated: true)
  658. // }
  659. }
  660. }
  661. } else {
  662. isStuckPointDataSuccess = true
  663. // 处理所有数据完成
  664. dealWithDataSuccess()
  665. }
  666. }
  667. /// 导出相册数据
  668. /// - Returns: <#description#>
  669. func exportPhotoData() {
  670. // 取消所有的导出
  671. PQSingletoMemoryUtil.shared.allExportSession.forEach { _, exportSession in
  672. exportSession.cancelExport()
  673. }
  674. var isHaveVideo: Bool = false
  675. if selectedPhotoData != nil, (selectedPhotoData?.count ?? 0) > 0 {
  676. if synchroMarskView.superview == nil {
  677. UIApplication.shared.keyWindow?.addSubview(synchroMarskView)
  678. }
  679. let dispatchGroup = DispatchGroup()
  680. for photo in selectedPhotoData! {
  681. if photo.asset != nil, photo.asset?.mediaType == .video{
  682. if !isHaveVideo {
  683. isHaveVideo = true
  684. }
  685. dispatchGroup.enter()
  686. PQPHAssetVideoParaseUtil.parasToAVAsset(phAsset: photo.asset!) { avAsset, fileSize, _, _ in
  687. if avAsset is AVURLAsset {
  688. // 创建目录
  689. let fileName = (avAsset as! AVURLAsset).url.absoluteString
  690. BFLog(message: "video fileName is\(fileName)")
  691. let tempPhoto = self.selectedPhotoData?.first(where: { material in
  692. material.asset == photo.asset
  693. })
  694. if(fileName.count ) > 0 {
  695. createDirectory(path: photoLibraryDirectory)
  696. let outFilePath = photoLibraryDirectory + fileName.md5 + ".mp4"
  697. // 文件存在先删除老文件
  698. if FileManager.default.fileExists(atPath: outFilePath) {
  699. do {
  700. try FileManager.default.removeItem(at: NSURL.fileURL(withPath: outFilePath))
  701. } catch {
  702. BFLog(message: "导出相册视频-error == \(error)")
  703. }
  704. }
  705. do{
  706. try FileManager.default.copyItem(atPath: fileName.replacingOccurrences(of: "file:///", with: ""), toPath: outFilePath)
  707. print("Success to copy file.")
  708. }catch{
  709. print("Failed to copy file.")
  710. }
  711. tempPhoto?.locationPath = outFilePath.replacingOccurrences(of: documensDirectory, with: "")
  712. BFLog(message: "导出视频相册地址为 \(String(describing: tempPhoto?.locationPath))")
  713. dispatchGroup.leave()
  714. }
  715. }
  716. }
  717. }
  718. }
  719. dispatchGroup.notify(queue: DispatchQueue.main) { [weak self] in
  720. self?.isExportVideosSuccess = true
  721. BFLog(message: "所有相册视频导出成功")
  722. // 处理所有数据完成
  723. if isHaveVideo {
  724. self?.dealWithDataSuccess()
  725. }
  726. }
  727. //只有图片
  728. if(!isHaveVideo){
  729. self.isExportVideosSuccess = true
  730. BFLog(message: "所有相册视频导出成功")
  731. self.dealWithDataSuccess()
  732. }
  733. }
  734. }
  735. /// 处理所有数据完成
  736. /// - Returns: <#description#>
  737. func dealWithDataSuccess() {
  738. BFLog(message: "三组参数:\(isSynchroMusicInfoSuccess) \(isStuckPointDataSuccess) \(isExportVideosSuccess)")
  739. if !isSynchroMusicInfoSuccess || !isStuckPointDataSuccess || !isExportVideosSuccess {
  740. return
  741. }
  742. playeTimeRange = CMTimeRange(start: CMTimeMakeWithSeconds(stuckPointMusicData?.startTime ?? 0, preferredTimescale: BASE_FILTER_TIMESCALE), end: CMTimeMakeWithSeconds(stuckPointMusicData?.endTime ?? 0, preferredTimescale: BASE_FILTER_TIMESCALE))
  743. createPorjectData()
  744. settingPlayerView()
  745. }
  746. }