|
@@ -61,6 +61,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
|
|
|
// 保存已经绘制的竖线用于变色使用
|
|
|
var lineLayerArray: Array = Array<CAShapeLayer>.init()
|
|
|
+ var lastDrawedLineIndex : Int = 0
|
|
|
|
|
|
// 裁剪区的相素大小
|
|
|
var cropViewWidth: CGFloat = adapterWidth(width: 250)
|
|
@@ -85,6 +86,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
var isUserDrag:Bool = false
|
|
|
// 推荐卡点起始时间
|
|
|
var suggestRhythmStartTime:CGFloat = 0.0
|
|
|
+ var suggestRhythmEndTime:CGFloat = 0.0
|
|
|
|
|
|
/// 滚动视图
|
|
|
lazy var scrollView: UIScrollView = {
|
|
@@ -165,13 +167,20 @@ class PQStuckPointCuttingView: UIView {
|
|
|
/// 更新卡点值
|
|
|
/// - Parameter endTime: endTime description
|
|
|
/// - Returns: <#description#>
|
|
|
- func updateEndTime(startTime: CGFloat, endTime: CGFloat) {
|
|
|
+ func updateEndTime(startTime: CGFloat, endTime: CGFloat,
|
|
|
+ suggestRhythmStartTime: CGFloat, suggestRhythmEndTime: CGFloat) {
|
|
|
+
|
|
|
+// videoDuration = duration
|
|
|
+ self.suggestRhythmStartTime = suggestRhythmStartTime
|
|
|
+ self.suggestRhythmEndTime = suggestRhythmEndTime
|
|
|
+ startLineX = 0
|
|
|
+
|
|
|
stuckPointStartTime = startTime
|
|
|
stuckPointEndTime = endTime
|
|
|
|
|
|
tatalTimeLabel.text = "\(Float64(stuckPointEndTime - stuckPointStartTime).formatDurationToHMS())"
|
|
|
|
|
|
- BFLog(1, message: "推荐开始\(stuckPointStartTime) 结束\(stuckPointEndTime) 时长为:\(stuckPointEndTime - stuckPointStartTime) 音乐总时长为:\(videoDuration)")
|
|
|
+ BFLog(1, message: "播放开始:\(stuckPointStartTime) 结束:\(stuckPointEndTime) 时长为:\(stuckPointEndTime - stuckPointStartTime); 音乐总时长为:\(videoDuration);推荐卡点开始:\(suggestRhythmStartTime) 结束:\(suggestRhythmEndTime)")
|
|
|
backgroundColor = PQBFConfig.shared.styleBackGroundColor
|
|
|
addSubview(scrollView)
|
|
|
|
|
@@ -181,6 +190,8 @@ class PQStuckPointCuttingView: UIView {
|
|
|
videoCropView.addSubview(tatalTimeLabel)
|
|
|
addData()
|
|
|
videoCropView.frame = CGRect(x: (cScreenWidth - cropViewWidth) / 2, y: 0, width: cropViewWidth, height: 80)
|
|
|
+ leftMaskView.frame = CGRect(x:0, y: 0, width: (cScreenWidth - cropViewWidth) / 2 - 2, height: 80)
|
|
|
+ rightMaskView.frame = CGRect(x:videoCropView.frame.maxX + 2, y: 0, width: (cScreenWidth - cropViewWidth) / 2 - 2, height: 80)
|
|
|
|
|
|
tatalTimeLabel.snp.remakeConstraints { make in
|
|
|
make.width.equalTo(40)
|
|
@@ -196,11 +207,19 @@ class PQStuckPointCuttingView: UIView {
|
|
|
// 1,选择区内的线个数 ,划动区域后 个数会变???
|
|
|
wavSelectCount = Int(ceil((cropViewWidth - frequencyWidth) / (frequencyWidth + frequencyMargin)) + 1)
|
|
|
|
|
|
- cropViewWidth = CGFloat(wavSelectCount - 1) * (frequencyWidth + frequencyMargin) + frequencyWidth
|
|
|
+ cropViewWidth = CGFloat(wavSelectCount) * (frequencyWidth + frequencyMargin) + frequencyWidth
|
|
|
+ margin = (cScreenWidth - cropViewWidth) / 2.0
|
|
|
+
|
|
|
|
|
|
// 2竖线一个间隔代表多少 S 是动态的
|
|
|
- oneMarginTime = (stuckPointEndTime - stuckPointStartTime) / CGFloat(wavSelectCount - 1)
|
|
|
+ oneMarginTime = (stuckPointEndTime - stuckPointStartTime) / CGFloat(wavSelectCount)
|
|
|
|
|
|
+ // 如果视频结束时间点大于歌曲有效结束点,则拼接推荐的时间段直到满足视频播放
|
|
|
+ var videoDurationTemp = suggestRhythmEndTime
|
|
|
+ while stuckPointEndTime > videoDurationTemp {
|
|
|
+ videoDurationTemp += (suggestRhythmEndTime - suggestRhythmStartTime)
|
|
|
+ }
|
|
|
+ videoDuration = videoDurationTemp
|
|
|
// 3,一共绘制的竖线个数
|
|
|
wavTotalCount = Int(ceil(videoDuration / oneMarginTime) + 1)
|
|
|
|
|
@@ -214,7 +233,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
}
|
|
|
scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.frame.height)
|
|
|
|
|
|
- BFLog(1, message: "框内个数:\(wavSelectCount), 总线条数:\(wavTotalCount), 框宽:\(cropViewWidth)")
|
|
|
+ BFLog(1, message: "框内个数:\(wavSelectCount), 总线条数:\(wavTotalCount), 框宽:\(cropViewWidth), 最终音乐时长:\(videoDuration)")
|
|
|
scrollView.subviews.forEach { lable in
|
|
|
if lable is UILabel && lable.tag != 66 {
|
|
|
lable.removeFromSuperview()
|
|
@@ -239,7 +258,6 @@ class PQStuckPointCuttingView: UIView {
|
|
|
// 2,滚动到推荐位置
|
|
|
if(!isUserDrag){
|
|
|
scrollView.contentOffset = CGPoint(x: startLineX - margin, y: 0)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
scrollView.addSubview(rateView)
|
|
@@ -273,24 +291,28 @@ class PQStuckPointCuttingView: UIView {
|
|
|
/// progress <#progress description#>
|
|
|
func updateProgress(progress: CGFloat) {
|
|
|
|
|
|
-
|
|
|
if(progress <= 0 || lineLayerArray.count == 0 || progress.isNaN){
|
|
|
BFLog(message: "progress is error ")
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
let startIndex = scrollView.contentOffset.x / (frequencyWidth + frequencyMargin)
|
|
|
- let selectIndex = Int(floor(startIndex + progress * CGFloat(wavSelectCount)))
|
|
|
- if(selectIndex < lineLayerArray.count){
|
|
|
- let drawLayer:CAShapeLayer = lineLayerArray[selectIndex]
|
|
|
- BFLog(message: "progress is \(progress) i \(selectIndex) 命中的位置:\(CGFloat(selectIndex) * oneMarginTime)")
|
|
|
+ lastDrawedLineIndex = max(lastDrawedLineIndex, Int(ceil(startIndex)))
|
|
|
+ let selectIndex = Int(ceil(startIndex + progress * CGFloat(wavSelectCount)))
|
|
|
+ while(selectIndex < lineLayerArray.count && selectIndex > lastDrawedLineIndex){
|
|
|
+ let drawLayer:CAShapeLayer = lineLayerArray[lastDrawedLineIndex]
|
|
|
if drawLayer.strokeColor != UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor{
|
|
|
+ BFLog(1, message: "progress is \(progress) i \(lastDrawedLineIndex) 命中的位置:\(CGFloat(lastDrawedLineIndex) * oneMarginTime)")
|
|
|
drawLayer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
|
|
|
drawLayer.setNeedsDisplay()
|
|
|
+ drawLayer.layoutIfNeeded()
|
|
|
}
|
|
|
+ lastDrawedLineIndex += 1
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
- if(progress >= 0.99){
|
|
|
+ if(progress >= 0.999){
|
|
|
BFLog(message: "播放完成 重新更新 UI ")
|
|
|
resetDefaultsColor(clearData: false)
|
|
|
}
|
|
@@ -299,6 +321,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
|
|
|
// 竖线恢复到原有色值
|
|
|
func resetDefaultsColor(clearData:Bool = true) {
|
|
|
+ lastDrawedLineIndex = 0
|
|
|
for layer in lineLayerArray {
|
|
|
layer.strokeColor = UIColor.hexColor(hexadecimal: "#999999").cgColor
|
|
|
layer.setNeedsDisplay()
|
|
@@ -318,7 +341,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
}
|
|
|
|
|
|
/// 生成波纹
|
|
|
- /// - Parameter waveArr: <#waveArr description#>
|
|
|
+ /// - Parameter waveArr: <#waveArr description#> // warning 有崩溃 _buffer _ArrayBuffer<CoreGraphics.CGFloat> wavearr为CoreGraph.CGFloat数组
|
|
|
/// - Returns: <#description#>
|
|
|
func createWave(waveArr: [CGFloat]) {
|
|
|
for (i, power) in waveArr.enumerated() {
|
|
@@ -345,9 +368,9 @@ class PQStuckPointCuttingView: UIView {
|
|
|
lineLayer.path = linePath.cgPath
|
|
|
lineLayer.fillColor = UIColor.black.cgColor
|
|
|
|
|
|
- // 推荐的开始起点是虚线
|
|
|
- BFLog(1, message: "suggestRhythmStartTime is \(suggestRhythmStartTime)")
|
|
|
- if oneMarginTime * CGFloat(i) >= suggestRhythmStartTime && !isDrawLine {
|
|
|
+ // 推荐的开始起点是虚线 减0.0001因为精度问题
|
|
|
+// BFLog(1, message: "suggestRhythmStartTime is \(suggestRhythmStartTime)")
|
|
|
+ if oneMarginTime * CGFloat(i) >= (suggestRhythmStartTime-0.0001) && !isDrawLine {
|
|
|
isDrawLine = true
|
|
|
linePath.move(to: CGPoint(x: originX, y: -10))
|
|
|
// 终点
|