CNLiveZFPlayerControlView.swift
7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// CNLiveZFPlayerControlView.swift
// metaCode
//
// Created by zx on 2025/2/27.
//
import Foundation
import ZFPlayer
//标清 2 ,高清 3 ,超清 4
typealias CNLiveVodPlayerControlLandscapeGaoqingUpdateBlock = (_ gaoqing:Int)->Void
typealias CNLiveVodPlayerPayBlock = (_ vodPlayModel : CNLiveVodPlayModel)->Void
typealias CNLiveVodPlayerControlLandscapeXuanjiUpdateBlock = (_ jishuIndex:Int,_ albumModel:CNLiveVodAlbumListModel)->Void
typealias CNLiveVodPlayerControlLandscapePauseBlock = ()->Void
class CNLiveZFPlayerControlView:ZFPlayerControlView{
//CNLiveVodPlayModel 单集model
var _vodPlayModel : CNLiveVodPlayModel?
var vodPlayModel : CNLiveVodPlayModel? {
get{
_vodPlayModel
}
set{
_vodPlayModel = newValue!
}
}
var pausePlayer:CNLiveVodPlayerControlLandscapePauseBlock?
var controlGaoqingUpdateBlock:CNLiveVodPlayerControlLandscapeGaoqingUpdateBlock?
var vodPlayerPayBlock:CNLiveVodPlayerPayBlock?
var controlXuanjiUpdateBlock:CNLiveVodPlayerControlLandscapeXuanjiUpdateBlock?
lazy var beiSuBtn: UIButton = {
let closeBtn = UIButton(type: .custom)
closeBtn.setTitle("倍速", for: .normal)
closeBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
closeBtn.titleLabel?.font = Font_12
closeBtn.addTarget(self, action: #selector(beiSuBtnAction), for: .touchUpInside)
closeBtn.backgroundColor = .clear
return closeBtn
}()
lazy var gaoqingBtn: UIButton = {
let closeBtn = UIButton(type: .custom)
closeBtn.setTitle("高清", for: .normal)
closeBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
closeBtn.titleLabel?.font = Font_12
closeBtn.addTarget(self, action: #selector(gaoqingBtnAction), for: .touchUpInside)
closeBtn.backgroundColor = .clear
return closeBtn
}()
lazy var xuanjiBtn: UIButton = {
let closeBtn = UIButton(type: .custom)
closeBtn.setTitle("选集", for: .normal)
closeBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
closeBtn.titleLabel?.font = Font_12
closeBtn.addTarget(self, action: #selector(xuanjiBtnAction), for: .touchUpInside)
closeBtn.backgroundColor = .clear
return closeBtn
}()
lazy var beiSuBgView :CNLiveVodLandscapeBeiSuView = {
let bottomNavView = CNLiveVodLandscapeBeiSuView()
return bottomNavView
}()
lazy var gaoqingBgView :CNLiveVodLandscapeGaoqingView = {
let bottomNavView = CNLiveVodLandscapeGaoqingView()
return bottomNavView
}()
lazy var xuanjiBgView :CNLiveVodLandscapeXuanjiView = {
let bottomNavView = CNLiveVodLandscapeXuanjiView()
return bottomNavView
}()
lazy var payBgView :CNLiveVodPayView = {
let bottomNavView = CNLiveVodPayView()
return bottomNavView
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI(){
self.landScapeControlView.bottomToolView.addSubview(self.beiSuBtn)
beiSuBtn.snp.makeConstraints { make in
make.left.equalTo(self.landScapeControlView.totalTimeLabel.snp.right).offset(5)
make.centerY.equalTo(self.landScapeControlView.slider.snp.centerY)
make.width.equalTo(40)
make.height.equalTo(30)
}
self.landScapeControlView.bottomToolView.addSubview(self.gaoqingBtn)
gaoqingBtn.snp.makeConstraints { make in
make.left.equalTo(self.beiSuBtn.snp.right)
make.centerY.equalTo(self.landScapeControlView.slider.snp.centerY)
make.width.equalTo(self.beiSuBtn.snp.width)
make.height.equalTo(self.beiSuBtn.snp.height)
}
self.landScapeControlView.bottomToolView.addSubview(self.xuanjiBtn)
xuanjiBtn.snp.makeConstraints { make in
make.left.equalTo(self.gaoqingBtn.snp.right)
make.centerY.equalTo(self.landScapeControlView.slider.snp.centerY)
make.width.equalTo(self.beiSuBtn.snp.width)
make.height.equalTo(self.beiSuBtn.snp.height)
}
self.addSubview(self.beiSuBgView)
beiSuBgView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
self.beiSuBgView.isHidden = true
self.beiSuBgView.beiSuUpdateBlock = {[weak self] rate in
guard let self = self else { return }
self.player?.currentPlayerManager.rate = rate
self.beiSuBgView.isHidden = true
}
self.addSubview(self.gaoqingBgView)
gaoqingBgView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
self.gaoqingBgView.isHidden = true
self.gaoqingBgView.gaoqingUpdateBlock = {[weak self] gaoqing in
guard let self = self else { return }
self.gaoqingBgView.isHidden = true
self.controlGaoqingUpdateBlock?(gaoqing)
}
self.addSubview(self.xuanjiBgView)
xuanjiBgView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
self.xuanjiBgView.isHidden = true
//横屏-选集-专辑 的某集
self.xuanjiBgView.xuanjiUpdateBlock = {[weak self] index,albumModel in
guard let self = self else { return }
//jishuIndex:Int,_ albumModel:CNLiveVodAlbumListModel
self.xuanjiBgView.isHidden = true
self.controlXuanjiUpdateBlock?(index,albumModel)
}
self.addSubview(self.payBgView)
payBgView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
self.payBgView.isHidden = true
self.payBgView.payBlock = {
//拉起内购
self.vodPlayerPayBlock?(self.vodPlayModel ?? CNLiveVodPlayModel())
}
}
override func layoutSubviews() {
super.layoutSubviews()
let min_margin = 9.0
let min_w = 62.0
let min_x = CGFloat(self.landScapeControlView.bottomToolView.width) - min_w - ((isiPhoneXSeries && UIApplication.shared.statusBarOrientation.isLandscape) ? 44.0: min_margin)
let min_y = 0.0
let min_h = 30.0
self.landScapeControlView.totalTimeLabel.frame = CGRect(x: min_x-130, y: min_y, width: min_w, height: min_h)
self.landScapeControlView.totalTimeLabel.centerY = self.landScapeControlView.playOrPauseBtn.centerY
let min_x1 = self.landScapeControlView.currentTimeLabel.right + 4.0
let min_y1 = 0.0
let min_w1 = self.landScapeControlView.totalTimeLabel.left - min_x1 - 4
let min_h1 = 30.0
self.landScapeControlView.slider.frame = CGRect(x: min_x1, y: min_y1, width: min_w1, height: min_h1)
self.landScapeControlView.slider.centerY = self.landScapeControlView.playOrPauseBtn.centerY
self.beiSuBtn.frame = CGRect(x: self.landScapeControlView.totalTimeLabel.right + 5.0, y: 0, width: 40, height: min_h1)
self.beiSuBtn.centerY = self.landScapeControlView.slider.centerY
// print("111111totalTimeLabel: \(self.landScapeControlView.totalTimeLabel)\n")
// print("11111slider: \(self.landScapeControlView.slider)\n")
// print("xuanjiBtn:\n \(self.xuanjiBtn)")
}
@objc func beiSuBtnAction(){
self.beiSuBgView.isHidden = false
// self.pausePlayer?()
}
@objc func gaoqingBtnAction(){
self.gaoqingBgView.isHidden = false
// self.pausePlayer?()
}
@objc func xuanjiBtnAction(){
self.xuanjiBgView.isHidden = false
// self.pausePlayer?()
}
}