CNLiveTVPlayerViewController.swift
45.2 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
//
// CNLivePlayerViewController.swift
// metaCode
//
// Created by zx on 2025/1/21.
//
import Foundation
import ZFPlayer
import MJRefresh
import HandyJSON
import CNLiveShareToolKit
import CNLivePayCostModule
class CNLiveTVPlayerViewController:UIViewController, UITableViewDataSource, UITableViewDelegate{
//专辑付费内容记录
var payVodAlbumListModel:CNLiveVodAlbumListModel?
var payContentId = ""
var payAid = ""
var payAlbumListArr = NSMutableArray()
var payIndex = 0
var payTitle = ""
var payIsAlbum = false
var payActivityId = ""
var isPayZhuanJi = false
var player: ZFPlayerController!
//当前内容id
var contentId = ""
var playTitle = ""
var isSeek = false
//当前播放列表 专辑true / 看点false
var isPlayAblumOrKandian = false
var isAblumVideo = false
//专辑列表数组 播放专辑时用
lazy var albumListArr: NSMutableArray = {
var dataArray = NSMutableArray()
return dataArray
}()
var albumIndex:Int = 0//当前专辑播放index
//看点列表数组 播放看点时用
lazy var kanDianListArr: NSMutableArray = {
var dataArray = NSMutableArray()
return dataArray
}()
var kanDianIndex:Int = -1//当前看点播放index
//CNLiveVodPlayModel 单集model
var _vodPlayModel : CNLiveVodPlayModel?
var vodPlayModel : CNLiveVodPlayModel? {
get{
_vodPlayModel
}
set{
_vodPlayModel = newValue!
}
}
// 专辑列表model
var _vodAlbumListBaseModel : CNLiveVodAlbumListBaseModel?
var vodAlbumListBaseModel : CNLiveVodAlbumListBaseModel? {
get{
_vodAlbumListBaseModel
}
set{
_vodAlbumListBaseModel = newValue!
}
}
//playerUrl
var _url:URL?
var url:URL? {
get{
return _url
}
set{
_url = newValue!
}
}
let kCNLiveVodIntroductionCellIdentifier = "kCNLiveVodIntroductionCellIdentifier"
let kCNLiveVodAlbumListCellIdentifier = "kCNLiveVodAlbumListCellIdentifier"
let kCNLiveVodTrailersCellIdentifier = "kCNLiveVodTrailersCellIdentifier"
let kCNLiveVodPlayShopCellIdentifier = "kCNLiveVodPlayShopCellIdentifier"
lazy var tableView : UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .none
tableView.register(CNLiveVodIntroductionCell.self, forCellReuseIdentifier: kCNLiveVodIntroductionCellIdentifier)
tableView.register(CNLiveVodAlbumListCell.self, forCellReuseIdentifier: kCNLiveVodAlbumListCellIdentifier)
tableView.register(CNLiveVodTrailersCell.self, forCellReuseIdentifier: kCNLiveVodTrailersCellIdentifier)
tableView.register(CNLiveVodPlayShopCell.self, forCellReuseIdentifier: kCNLiveVodPlayShopCellIdentifier)
tableView.backgroundColor = .white
return tableView
}()
///数据源
lazy var dataArray: NSMutableArray = {
var dataArray = NSMutableArray()
return dataArray
}()
lazy var bottomCommentShowContainView :UIView = {
let iconImgView = UIView()
iconImgView.backgroundColor = .clear
return iconImgView
}()
lazy var bottomCommentView :UIView = {
let iconImgView = UIView(frame: CGRect(x: 0, y: KSreenHeight-60-KTabBarSafeHeight, width: KSreenWidth, height: 60))
iconImgView.backgroundColor = .white
iconImgView.isUserInteractionEnabled = true
iconImgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(bottomCommentViewTapAction)))
return iconImgView
}()
lazy var bottomCommentTalkView :UIView = {
let iconImgView = UIView()
iconImgView.layer.borderColor = HexColor("#979797")?.cgColor
iconImgView.layer.borderWidth = 0.5
iconImgView.layer.cornerRadius = 20
iconImgView.clipsToBounds = true
return iconImgView
}()
lazy var bottomCommentLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.text = "我来说几句…"
titleLabel.textColor = HexColor("#999999")
titleLabel.textAlignment = .left
titleLabel.font = Font_14
return titleLabel
}()
lazy var bottomCommentImgView :UIImageView = {
let iconImgView = UIImageView()
iconImgView.image = UIImage(named: "home_player_comment")
return iconImgView
}()
lazy var whitBgView :UIView = {
let iconImgView = UIView(frame: CGRect(x: 0, y: KStatusBarHeight, width: KSreenWidth, height: KSreenHeight-KStatusBarHeight))
iconImgView.backgroundColor = .white
return iconImgView
}()
lazy var containerView :UIImageView = {
let iconImgView = UIImageView(frame: CGRect(x: 0, y: KStatusBarHeight, width: KSreenWidth, height: KSreenWidth*9/16))
iconImgView.image = UIImage.imageWithColor(color: UIColor.black, size: CGSize(width: 1, height: 1))
return iconImgView
}()
lazy var controlView :CNLiveZFPlayerControlView = {
let controlView = CNLiveZFPlayerControlView()
controlView.fastViewAnimated = true
controlView.autoHiddenTimeInterval = 5
controlView.autoFadeTimeInterval = 0.5
controlView.prepareShowLoading = true
controlView.prepareShowControlView = false
controlView.showCustomStatusBar = true
return controlView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
self.view.addSubview(self.whitBgView)
self.view.addSubview(self.containerView)
let backBtn = UIButton.backItem(imageName: ("mine_header_icon_white_back"), target: self, action: #selector(ClickBackBtn))
backBtn.frame = CGRect(x: 15, y: KStatusBarHeight, width: backBtn.width, height: backBtn.height)
self.view.addSubview(backBtn)
// backBtn.backgroundColor = .red
self.setupPlayer()
view.addSubview(tableView)
tableView.frame = CGRect(x: 0, y: self.containerView.bottom, width: KSreenWidth, height: KSreenHeight-self.containerView.bottom-KTabBarSafeHeight-60)
view.addSubview(self.bottomCommentView)
self.bottomCommentView.addSubview(self.bottomCommentTalkView)
bottomCommentTalkView.snp.makeConstraints { make in
make.top.left.equalToSuperview().offset(10)
make.width.equalToSuperview().offset(-75)
make.height.equalTo(40)
}
self.bottomCommentView.addSubview(self.bottomCommentLabel)
bottomCommentLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(25)
make.centerY.equalToSuperview()
make.width.equalTo(100)
make.height.equalTo(20)
}
self.bottomCommentView.addSubview(self.bottomCommentImgView)
bottomCommentImgView.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-20)
make.centerY.equalToSuperview()
make.width.equalTo(25)
make.height.equalTo(24)
}
self.view.addSubview(self.bottomCommentShowContainView)
bottomCommentShowContainView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.top.equalToSuperview().offset(self.containerView.bottom)
make.width.equalToSuperview()
make.height.equalToSuperview().offset(-self.containerView.bottom)
}
bottomCommentShowContainView.isHidden = true
// self.addRefreshView()
self.configDataArray()
self.isAblumVideo = false
self.isPlayAblumOrKandian = false
// if let albumModel = self.vodAlbumListBaseModel{
if self.vodPlayModel?.album?.albumId.count ?? 0 > 0{
//专辑
self.isAblumVideo = true
self.isPlayAblumOrKandian = true
}else{
//单集
self.isAblumVideo = false
self.isPlayAblumOrKandian = false
}
}
func configDataArray(){
//配置数据
var tempDataArray = NSMutableArray()
//单集 简介
if let vodPlayModel = self.vodPlayModel{//单集有值-简介
for (_,mdl) in vodPlayModel.blockList.enumerated(){
if mdl.type == "5"{//点播详情数据
//CNLiveVodPlayBlockListModel
tempDataArray.add(mdl)
}
}
}
//专辑-简介
if let vodAlbumListBaseModel = self.vodAlbumListBaseModel{//专辑有值-专辑列表
if let mdl = vodAlbumListBaseModel.list.first{
if let msgModel = mdl.vodAlbumMsgModel{
let tempArr = NSMutableArray(array: tempDataArray as! [Any])
if let vodMdl = tempArr.firstObject as? CNLiveVodPlayBlockListModel{
for firMdl in vodMdl.list{
firMdl.title = msgModel.albumName
firMdl.desc = msgModel.desc
}
tempDataArray.removeAllObjects()
tempDataArray.add(vodMdl)
}
}
}
}
//专辑有值-专辑列表
if let vodAlbumListBaseModel = self.vodAlbumListBaseModel{//专辑有值-专辑列表
tempDataArray.add(vodAlbumListBaseModel)
}
//看点
///**blockList.type 1/2/3/4/5 商品入口/片花资讯/活动推荐/相关推荐/点播详情 */
if let vodPlayModel = self.vodPlayModel{//单集有值-简介
for (_,mdl) in vodPlayModel.blockList.enumerated(){
if mdl.type == "2"{//看点list数据
//CNLiveVodPlayBlockListModel
tempDataArray.add(mdl)
}
}
}
//商品
if let vodPlayModel = self.vodPlayModel{//单集有值
if vodPlayModel.goodsJson.count > 0{
let goodMdls = jsonArrayToModel(vodPlayModel.goodsJson, CNLiveVodPlayShopModel.self)
if goodMdls.count > 0{//CNLiveVodPlayModel [CNLiveVodPlayShopModel]
//有商品
tempDataArray.add(goodMdls)
}else{
//没商品
}
}
}
self.dataArray = NSMutableArray(array: tempDataArray)
}
func setupNewUI(model:CNLiveDownSlideContentsModel){
}
// MARK: - 播放相关
func setupPlayer(){
let playerManager = ZFAVPlayerManager()
playerManager.shouldAutoPlay = true
player = ZFPlayerController(playerManager: playerManager, containerView: containerView)
player.pauseWhenAppResignActive = false
player.controlView = controlView
//不跟随设备旋转
player.allowOrentitaionRotation = true
self.player.orientationDidChanged = {[weak self] player,isFullScreen in
guard let self = self else { return }
}
var endAssetURL:URL?
/// 播放完成
self.player.playerDidToEnd = {
[weak self] asset in
guard let self = self else { return }
if endAssetURL == nil {
endAssetURL = asset.assetURL
self.playNextIfExist()
}else{
//一个视频回调 两次end
endAssetURL = nil
}
let delayTime = DispatchTime.now()+3
DispatchQueue.main.asyncAfter(deadline: delayTime) {
endAssetURL = nil
}
}
var urls = [URL]()
urls.append(self.url!)
self.player.assetURLs = urls
self.player.playTheIndex(0)
var title = ""
if self.vodPlayModel?.blockList.count ?? 0 > 0{
for mdl in self.vodPlayModel!.blockList{
if mdl.type == "5"{//详情
if mdl.list.count > 0{
let vodModel = mdl.list[0]
title = vodModel.title
}
}
}
}
self.controlView.showTitle(title, cover: UIImage.imageWithColor(color: .darkGray, size: CGSize(width: 50, height: 50)), fullScreenMode: .landscape)
self.playTitle = title
self.controlView.vodPlayerPayBlock = {[weak self] in
guard let self = self else { return }
//支付按钮,拉起内购
//成功用pay参数 刷新页面
let orderId = CNLiveHomePageViewModel.getRandomOrderId()
let notifyUrl = "http://apps.pay.cnlive.com/upappnotify/notify/orderForVideo"
//分转元,没有小数点
let fenString = self.payVodAlbumListModel?.product?.iosRmb ?? "100"
// 将字符串转换为整数
// 使用guard语句确保字符串可以转换为整数
guard let fen = Int(fenString) else {
print("无法将字符串转换为整数")
return
}
// 计算元值(整数除法,自动舍去小数部分)
var yuan = fen / 100
if yuan <= 0{//如果是测试0.1元 ,线上默认设置为1元
yuan = 1
}
// 将结果转换为字符串
let yuanString = String(yuan)
let prdId = "com.cnlive.metaCode."+yuanString//"com.cnlive.metaCode."+"1"//+(viewcell.homeModel.albumMsgModel?.product?.iosRmb ?? "1")
let body = self.payVodAlbumListModel?.product?.productTitle ?? ""
let total_fee = yuan*100
let dataDic = NSMutableDictionary()
dataDic.setValue(body, forKey: "body")
dataDic.setValue(notifyUrl, forKey: "notify_url")
dataDic.setValue(orderId, forKey: "orderId")
dataDic.setValue(prdId, forKey: "prdId")
dataDic.setValue(total_fee, forKey: "total_fee")
//后台设置一个 com.cnlive.meta.1 2 60 3 78
//苹果内购暂时报错 验证失败支付失败
CNLivePayCostModule.showApplePayViw(withParamDict: dataDic as! [AnyHashable : Any], fromVC: currentViewController()!) {[weak self] result in
guard let self = self else { return }
if result == CNLivePayCostTypeResultSucc{
print("succ")
//刷新页面
self.contentId = self.payContentId
self.refreshVodData(isAblumVideo: self.payIsAlbum)
self.controlView.payBgView.isHidden = true
self.player.allowOrentitaionRotation = true
}
}
}
self.controlView.controlGaoqingUpdateBlock = { [weak self] gaoqing in
guard let self = self else { return }
//
CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: self.vodPlayModel?.contentId ?? "", rate: gaoqing) { result, status in
if status == .success{
if let url = result as? String{
self.seekPlayerWithUrlAndTitle(url: url, title: self.playTitle, seekTime: self.player.currentTime)
}
}
}
}
}
func playNextIfExist(){
if self.isAblumVideo && self.isPlayAblumOrKandian{
//当前播放的是 专辑列表 ,播专辑列表下一条
let nextIdx = self.albumIndex + 1
if nextIdx < self.albumListArr.count{
self.albumIndex = nextIdx
if let albumModel = self.albumListArr[nextIdx] as? CNLiveVodAlbumListModel{
//播专辑列表下一条
self.kanDianOrAlbumChangeContentApi(contentId: albumModel.contentId, title: albumModel.title, isAlbum: self.isAblumVideo, activeId: albumModel.activityId)
// self.changeContentApi(vodModel: albumModel)
}
}else{
// self.player.stop()
}
}else{
//当前播放的是 看点列表 ,播看点列表下一条
let nextIdx = self.kanDianIndex + 1
if nextIdx < self.kanDianListArr.count{
self.kanDianIndex = nextIdx
self.albumIndex = -1
if let albumModel = self.kanDianListArr[nextIdx] as? CNLiveVodPlayBlockListListModel{
//播列表下一条
let isAblumVideo = (albumModel.album?.albumId.count ?? 0 > 0) ? true : false
// if isAblumVideo{
self.kanDianOrAlbumChangeContentApi(contentId: albumModel.contentId, title: albumModel.title, isAlbum: isAblumVideo, activeId: albumModel.pid)
// }else{
// self.kanDianOrAlbumChangeContentApi(contentId: albumModel.contentId, title: albumModel.title, isAlbum: isAblumVideo, activeId: albumModel.pid)
// }
// self.changeContentApi(vodModel: albumModel)
}
}else{
// self.player.stop()
}
}
// if (!self.player.isLastAssetURL) {
// [self.player playTheNext];
// NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
// [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape];
// } else {
// [self.player stop];
// }
}
//播放url更换title
func playWithUrlAndTitle(url:String,title:String){
if self.isSeek{
}else{
self.controlView.gaoqingBgView.resetGaoqing()
}
self.isSeek = false
self.player.currentPlayerManager.rate = 1.0
self.playTitle = title
self.url = URL(string: url)
var urls = [URL]()
urls.append(self.url!)
self.player.assetURLs = urls
self.player.playTheIndex(0)
self.controlView.showTitle(title, cover: UIImage.imageWithColor(color: .darkGray, size: CGSize(width: 50, height: 50)), fullScreenMode: .landscape)
}
func seekPlayerWithUrlAndTitle(url:String,title:String,seekTime:TimeInterval){
self.isSeek = true
self.playWithUrlAndTitle(url: url, title: title)
self.player.seek(toTime: seekTime)
}
//单集 更换contentId内容 play接口刷新看点和电商
func vodChangeContentApi(vodModel:CNLiveVodAlbumListModel){
//刷新url
CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: vodModel.activityId) {[weak self] result, status in
guard let self = self else { return }
if status == .success
{
if let url = result as? String{
self.playWithUrlAndTitle(url: url, title: vodModel.title)
}
}else{
}
}
//play接口刷新 看点和电商
CNLiveDownSlideTool.getVodPlayApi(contentId: vodModel.contentId) {[weak self] result, status in
guard let self = self else { return }
if status == .success{
if let vodPlayModel = result as? CNLiveVodPlayModel{
self.vodPlayModel = vodPlayModel
self.configDataArray()
self.tableView.reloadData()
}else{
}
}else{
}
}
}
func destroyPlayer(){
self.player.stop()
}
// MARK: - 专辑/看点 列表切换某集,只刷新播放器和点赞收藏
func kanDianOrAlbumChangeContentApi(contentId:String,title:String,isAlbum:Bool,activeId:String){
// if isAlbum{
self.changeContentApi(activityId: activeId, title: title, contentId: contentId)
// }else{
// self.kanDianChangeContentApi(contentId: contentId, title: title)
// }
}
// MARK: - 看点列表切换某集 只刷新播放器和点赞收藏
func kanDianChangeContentApi(contentId:String,title:String){
self.isPlayAblumOrKandian = false
//刷新url
CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: contentId) {[weak self] result, status in
guard let self = self else { return }
if status == .success
{
if let url = result as? String{
self.playWithUrlAndTitle(url: url, title: title)
self.url = URL(string: url)
}
}else{
}
}
//play接口刷新 看点和电商
CNLiveDownSlideTool.getVodPlayApi(contentId: contentId) {[weak self] result, status in
guard let self = self else { return }
if status == .success{
if let vodPlayModel = result as? CNLiveVodPlayModel{
// self.vodPlayModel = vodPlayModel
//单集有值-简介
var index = 0
var isReplace = false
var tempMdl:CNLiveVodPlayBlockListModel?
for (idx,mdl) in self.dataArray.enumerated(){
if var tempVodMdl = mdl as? CNLiveVodPlayBlockListModel{
if tempVodMdl.type == "5"{//点播详情数据
for (_,vodMdl) in vodPlayModel.blockList.enumerated(){
if vodMdl.type == "5"{
tempMdl = vodMdl
index = idx
isReplace = true
}
}
}
}
}
if isReplace{
self.dataArray.replaceObject(at: index, with: tempMdl as Any)
}else{}
self.configDataArray()
self.tableView.reloadData()
}else{
}
}else{
}
}
}
// MARK: -专辑列表切换某集 ,刷新看点和电商
func changeContentApi(activityId:String,title:String,contentId:String){
// self.isPlayAblumOrKandian = true
//play接口刷新 看点和电商 1350755
CNLiveDownSlideTool.getVodPlayApi(contentId: contentId) {[weak self] result, status in
guard let self = self else { return }
if status == .success{
if var vodPlayModel = result as? CNLiveVodPlayModel{
// self.vodPlayModel = vodPlayModel
//单集有值-简介
var temp5Mdl:CNLiveVodPlayBlockListModel?
var temp2Mdl:CNLiveVodPlayBlockListModel?
var tempVodPlayModel = self.vodPlayModel
for (_,vodMdl) in vodPlayModel.blockList.enumerated(){
if vodMdl.type == "5"{
temp5Mdl = vodMdl
}
if vodMdl.type == "2"{
temp2Mdl = vodMdl
}
}
for(index,vodModel) in tempVodPlayModel!.blockList.enumerated(){
if self.isPlayAblumOrKandian{
//切换剧集时, 调用play接口, 更新片花列表和商品列表
if temp2Mdl != nil{
if vodModel.type == "2"{//更新片花
tempVodPlayModel!.blockList[index] = temp2Mdl!
}
}
}else{
//切换看点时, 调用play接口, 只更新商品列表
}
//更新简介里的 点赞和收藏 简介
if temp5Mdl != nil{
if vodModel.type == "5"{
tempVodPlayModel!.blockList[index] = temp5Mdl!
}
}
}
tempVodPlayModel?.goodsJson = vodPlayModel.goodsJson
self.vodPlayModel = tempVodPlayModel
//刷新url 1955_71512cfbcd5b497580732b48e26d16d6
CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: activityId) {[weak self] result, status in
guard let self = self else { return }
if status == .success
{
if let url = result as? String{
self.playWithUrlAndTitle(url: url, title: title)
self.url = URL(string: url)
}
}else{
}
}
self.configDataArray()
self.tableView.reloadData()
}else{
}
}else{
}
}
}
// MARK: - 专辑刷新整个页面
func refreshVodData(isAblumVideo:Bool){
CNLiveDownSlideTool.getVodData(contentId: self.payAid, isAblumVideo: isAblumVideo,seleContentId: self.payContentId) {[weak self] vodPlayModel, contentId,url, result, status in
guard let self = self else { return }
if status == .success{
self.vodPlayModel = vodPlayModel
self.contentId = contentId
if let vodAlbumListBaseModel = result{
self.vodAlbumListBaseModel = vodAlbumListBaseModel
}
self.url = URL(string: url)
self.configDataArray()
self.albumIndex = self.payIndex
self.tableView.mj_header?.endRefreshing()
self.tableView.reloadData()
var title = ""
for (_,mdl) in vodPlayModel.blockList.enumerated(){
if mdl.type == "5" && mdl.list.count > 0 {//点播详情数据
//CNLiveVodPlayBlockListListModel
if let playMdl = mdl.list.first as? CNLiveVodPlayBlockListListModel{
title = playMdl.title
}
}
}
self.playWithUrlAndTitle(url: url, title: title)
}else{
}
}
}
// MARK: - UITableViewDelegate
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let vodPlayBlockListModel = self.dataArray[indexPath.row] as? CNLiveVodPlayBlockListModel{
if vodPlayBlockListModel.type == "5"{
//点播详情
//简介-标题描述,点赞评论分享
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVodIntroductionCellIdentifier) as? CNLiveVodIntroductionCell
else {
let cell = CNLiveVodIntroductionCell()
return cell
}
cell.vodPlayBlockListModel = vodPlayBlockListModel
cell.updateCellBlock = {[weak self] isExpand,isFavorite,isCollection,type,vodPlayBlockListListModel in
guard let self = self else { return }
if type == "1"{
//点击了详情按钮
self.introducCellDetailBtnAction(vodPlayBlockListListModel: vodPlayBlockListListModel)
}else if type == "2"{
//点击了点赞按钮
self.vodSupport(vodPlayBlockListListModel: vodPlayBlockListListModel, isLiked: isFavorite)
}else if type == "3"{
//点击了收藏按钮
self.vodCollection(vodPlayBlockListListModel: vodPlayBlockListListModel, isCollectioned: isCollection)
}else if type == "4"{
//点击了分享按钮
self.vodShare(vodPlayBlockListListModel: vodPlayBlockListListModel)
}
}
return cell
}else if vodPlayBlockListModel.type == "2"{//看点
//看点
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVodTrailersCellIdentifier) as? CNLiveVodTrailersCell
else {
let cell = CNLiveVodTrailersCell()
return cell
}
cell.currSeleIdx = self.kanDianIndex//-1
cell.vodPlayBlockListModel = vodPlayBlockListModel
cell.expandBlock = { [weak self] model in
guard let self = self else { return }
self.trailersCellDetailBtnAction(vodPlayBlockListModel: model)
}
cell.selectBlock = { [weak self] model,index,kanDianListArr in
guard let self = self else { return }
self.contentId = model.contentId
let isAblumVideo = (model.album?.albumId.count ?? 0 > 0) ? true : false
// let isAblumVideo = model.model == "1" ? false : true
self.albumIndex = -1
self.kanDianIndex = index
self.kanDianListArr = kanDianListArr
//只更新 此视频的长id,换url(不管是不是专辑)
self.isPlayAblumOrKandian = false
self.kanDianOrAlbumChangeContentApi(contentId: model.contentId, title: model.title, isAlbum: isAblumVideo, activeId: model.pid)
// self.refreshVodData(isAblumVideo: isAblumVideo)
}
return cell
}else{
}
}else if let vodAlbumListBaseModel = self.dataArray[indexPath.row] as? CNLiveVodAlbumListBaseModel{
//专辑列表
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVodAlbumListCellIdentifier) as? CNLiveVodAlbumListCell
else {
let cell = CNLiveVodAlbumListCell()
return cell
}
cell.currSeleIdx = self.albumIndex
cell.vodAlbumListBaseModel = vodAlbumListBaseModel
cell.selectBlock = {[weak self] vodModel, index ,albumListArr in
guard let self = self else { return }
self.player.currentPlayerManager.pause()
isPayZhuanJi = false//是否付过费
var yuanString = "1"
if vodModel.product?.check == true {
//免费或者付过费了
self.controlView.payBgView.isHidden = true
isPayZhuanJi = true
} else {
if vodModel.product?.productType == "4" {
//这里表示可以进行试听
self.controlView.payBgView.isHidden = true
isPayZhuanJi = true
} else {
//需要付费
self.controlView.payBgView.isHidden = false
isPayZhuanJi = false
//分转元,没有小数点
let fenString = vodModel.product!.iosRmb
// 将字符串转换为整数
// 使用guard语句确保字符串可以转换为整数
guard let fen = Int(fenString) else {
print("无法将字符串转换为整数")
return
}
// 计算元值(整数除法,自动舍去小数部分)
var yuan = fen / 100
if yuan <= 0{//如果是测试0.1元 ,线上默认设置为1元
yuan = 1
}
// 将结果转换为字符串
yuanString = String(yuan)
}
}
if isPayZhuanJi{
//已经付费
self.controlView.payBgView.isHidden = true
self.contentId = vodModel.contentId
self.albumListArr = albumListArr
self.albumIndex = index
self.kanDianIndex = -1
self.isPlayAblumOrKandian = true
self.kanDianOrAlbumChangeContentApi(contentId: vodModel.contentId, title: vodModel.title, isAlbum: true, activeId: vodModel.activityId)
self.player.allowOrentitaionRotation = true
}else{
//没付费
//显示付费页面
self.controlView.payBgView.isHidden = false
self.controlView.payBgView.payBtn.setTitle("\(yuanString)元购买本专辑", for: .normal)
//成功用pay参数 刷新页面
self.payVodAlbumListModel = vodModel
self.payAid = vodModel.albumId//.contentId
self.payContentId = vodModel.contentId
self.payAlbumListArr = albumListArr
self.payIndex = index
self.kanDianIndex = -1
self.isPlayAblumOrKandian = true
self.payTitle = vodModel.title
self.payIsAlbum = true
self.payActivityId = vodModel.activityId
self.player.allowOrentitaionRotation = false
}
}
return cell
}else if let vodPlayShopModels = self.dataArray[indexPath.row] as? [CNLiveVodPlayShopModel]{
//电商
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVodPlayShopCellIdentifier) as? CNLiveVodPlayShopCell
else {
let cell = CNLiveVodPlayShopCell()
return cell
}
cell.vodPlayShopModels = vodPlayShopModels
cell.expandBlock = {[weak self] vodPlayShopModels in
guard let self = self else { return }
self.shopCellDetailBtnAction(vodPlayShopModels: vodPlayShopModels)
}
return cell
}else {
return UITableViewCell()
}
return UITableViewCell()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if let vodPlayBlockListModel = self.dataArray[indexPath.row] as? CNLiveVodPlayBlockListModel{
if vodPlayBlockListModel.type == "5"{
//点播详情
//简介-标题描述,点赞评论分享
return 112
}else if vodPlayBlockListModel.type == "2"{
//看点
return 25+106+76
}else{
}
}else if let vodAlbumListBaseModel = self.dataArray[indexPath.row] as? CNLiveVodAlbumListBaseModel{
//专辑列表
return 50+15
}else if let vodPlayShopModels = self.dataArray[indexPath.row] as? [CNLiveVodPlayShopModel]{
//电商
return 145.0
}else {
}
return 100
}
func addRefreshView() {
tableView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {[weak self] in
self!.refreshVodData(isAblumVideo: self!.isAblumVideo)
})
}
override var preferredStatusBarStyle: UIStatusBarStyle{
return .lightContent
}
override var prefersStatusBarHidden: Bool{
return false
}
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{
return .none
}
override var shouldAutorotate: Bool{
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
return .allButUpsideDown
}
func shopCellDetailBtnAction(vodPlayShopModels:[CNLiveVodPlayShopModel]) {
bottomCommentShowContainView.isHidden = false
let detailBgView = CNLiveVodShopBottomView(frame: bottomCommentShowContainView.bounds)
detailBgView.backgroundColor = .white
bottomCommentShowContainView.addSubview(detailBgView)
detailBgView.vodPlayShopModels = vodPlayShopModels
detailBgView.expandHideBlock = {[weak self] in
guard let self = self else { return }
self.bottomCommentShowContainView.removeAllSubviews()
self.bottomCommentShowContainView.isHidden = true
}
}
// MARK: - 看点cell展开
func trailersCellDetailBtnAction(vodPlayBlockListModel:CNLiveVodPlayBlockListModel) {
bottomCommentShowContainView.isHidden = false
let detailBgView = CNLiveVodCellBottomView(frame: bottomCommentShowContainView.bounds)
detailBgView.backgroundColor = .white
bottomCommentShowContainView.addSubview(detailBgView)
detailBgView.vodPlayBlockListModel = vodPlayBlockListModel
detailBgView.expandHideBlock = {[weak self] in
guard let self = self else { return }
self.bottomCommentShowContainView.removeAllSubviews()
self.bottomCommentShowContainView.isHidden = true
}
detailBgView.updateBlock = {[weak self] seleIdx,model in
guard let self = self else { return }
self.contentId = model.contentId
var isAblumVideo = false
// let isAblumVideo = (model.album?.albumId.count ?? 0 > 0) ? true : false
if model.album?.albumId.count ?? 0 > 0{
isAblumVideo = true
}else{
isAblumVideo = false
}
// if model.model == "1"{
// isAblumVideo = false
// }else{
// isAblumVideo = true
// }
self.isPlayAblumOrKandian = false
self.kanDianOrAlbumChangeContentApi(contentId: model.contentId, title: model.title, isAlbum: isAblumVideo, activeId: model.pid)
// self.refreshVodData(isAblumVideo: isAblumVideo)
}
}
// MARK: - 简介cell点击事件
func introducCellDetailBtnAction(vodPlayBlockListListModel:CNLiveVodPlayBlockListListModel) {
bottomCommentShowContainView.isHidden = false
let detailBgView = UIView(frame: bottomCommentShowContainView.bounds)
detailBgView.backgroundColor = .white
bottomCommentShowContainView.addSubview(detailBgView)
let vodMdl = vodPlayBlockListListModel
let titleLbl = UILabel()
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#000102")
titleLbl.text = vodMdl.title
bottomCommentShowContainView.addSubview(titleLbl)
titleLbl.snp.makeConstraints { make in
make.left.equalTo(10)
make.top.equalTo(16)
make.width.lessThanOrEqualTo(KSreenWidth-50)
}
let detailLbl = UILabel()
detailLbl.font = Font_10
detailLbl.textColor = HexColor("#999999")
detailLbl.text = "详情"
bottomCommentShowContainView.addSubview(detailLbl)
detailLbl.snp.makeConstraints { make in
make.left.equalTo(titleLbl.snp.right).offset(15)
make.top.equalTo(20.5)
make.width.equalTo(21)
make.height.equalTo(14)
}
let descLbl = UITextView()
descLbl.font = Font_13
descLbl.textColor = HexColor("#999999")
descLbl.text = vodMdl.desc
descLbl.width = KSreenWidth-20
bottomCommentShowContainView.addSubview(descLbl)
descLbl.snp.makeConstraints { make in
make.left.equalTo(10)
make.top.equalTo(titleLbl.snp.bottom).offset(10)
make.right.equalToSuperview().offset(-20)
make.bottom.equalToSuperview().offset(-15-50-10)
}
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.setImage(UIImage(named: "home_player_unexpand"), for: .normal)
expandBtn.addTarget(self, action: #selector(expandBtnAction), for: .touchUpInside)
bottomCommentShowContainView.addSubview(expandBtn)
expandBtn.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(-15)
make.width.equalTo(50)
make.height.equalTo(50)
}
}
func vodSupport(vodPlayBlockListListModel:CNLiveVodPlayBlockListListModel,isLiked:Bool){
CNLiveVodPlayViewModel.vodSupport(contentId: vodPlayBlockListListModel.pid, support: isLiked) {[weak self] result, status in
guard let self = self else { return }
if status == .success{
}
}
}
func vodCollection(vodPlayBlockListListModel:CNLiveVodPlayBlockListListModel,isCollectioned:Bool){
let type = isCollectioned ? "1" : "2"
CNLiveVodPlayViewModel.vodCollection(type: type, vodPlayBlockListListModel: vodPlayBlockListListModel) {[weak self] result, status in
guard let self = self else { return }
if status == .success{
//不改数据了
}
}
}
func vodShare(vodPlayBlockListListModel:CNLiveVodPlayBlockListListModel){
CNLiveShareManager.showShareViewWithParam(forShareTitle: vodPlayBlockListListModel.title, shareUrl: "https://wjjh5.cnlive.com/apkdownloadYuanma.php", shareDesc: vodPlayBlockListListModel.desc, shareImage: vodPlayBlockListListModel.img, screenFull: false, hiddenWjj: true, hiddenQQ: false, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: false, formVC: currentViewController(), topImage: [], topTitles: [], platformType: .all) { title in
} completerBlock: { resultType, platformType, typeString in
if resultType == .succ{
}
}
}
// MARK: - ButtonAction
@objc func expandBtnAction() {
//详情 收起
self.bottomCommentShowContainView.removeAllSubviews()
self.bottomCommentShowContainView.isHidden = true
}
@objc func bottomCommentViewTapAction() {
bottomCommentShowContainView.isHidden = false
//评论
CNLiveShortVideoCommentListView.showVideoCommentListView(pid: self.vodPlayModel?.contentId ?? "", contentSid: UserInfoManager.shared.userInfo.uid,containView:self.bottomCommentShowContainView, result: { commentModel in
print("\(commentModel)")
}, close: {
self.bottomCommentShowContainView.isHidden = true
})
}
@objc func ClickBackBtn() {
let viewControllers = self.navigationController?.viewControllers
if viewControllers?.count ?? 0 > 1 {
if viewControllers?.last == self {
self.navigationController!.popViewController(animated: true)
}
}
}
// MARK: - 点播play接口
/*
func requestGetVodPlayApi(contentId:String){
CNLiveHomePageViewModel.requestGetVodPlayApi(contentId: contentId, sid: UserInfoManager.shared.userInfo.uid, resultBlock: { result, status in
if status == .success{
if let vodPlayMpdel = result as? CNLiveVodPlayModel{
if let albumMdl = vodPlayMpdel.album{
//专辑
self.requestGetVodPlay1Api(contentId: vodPlayMpdel.contentId)
//记录当前播放集数的ContentId
self.contentId = vodPlayMpdel.contentId
self.requestGetAlbumMsgApi(contentId: vodPlayMpdel.contentId)
}else{
//单集
}
}
}
})
}
//专辑的单集内容
func requestGetVodPlay1Api(contentId:String){
CNLiveHomePageViewModel.requestGetVodPlayApi(contentId: contentId, sid: UserInfoManager.shared.userInfo.uid, resultBlock: { result, status in
if status == .success{
if let vodPlayMpdel = result as? CNLiveVodPlayModel{
if let albumMdl = vodPlayMpdel.album{
//专辑
}else{
//单集
}
}
}
})
}
*/
// MARK: - 专辑内容详情
// func requestGetAlbumMsgApi(contentId:String){
// CNLiveHomePageViewModel.requstWithVodAlbumMsgVideo(aid: contentId, resultBlock: { result, status in
// if status == .success{
// if let vodPlayMpdel = result as? CNLiveVodPlayModel{
// //专辑详情
// }
// }
// })
// }
deinit {
print("vod deinit")
}
}