杨锴
2024-11-07 62a24b3c7cf92919a93ee575e9460037e1a53816
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
//
//  CourseDetialVideoVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/19.
//
 
import UIKit
import JQTools
 
class CourseDetialVideoVC: BaseVC {
 
                @IBOutlet weak var view_bg_video: UIView!
                @IBOutlet weak var tableView: UITableView!
 
                private var videoView:VideoView?
                private var items = [CourseItemModel]()
                private var selectIndex:IndexPath!
    private var secondLook:Int = 0
    private var isOver:Bool = false
 
                override func viewWillAppear(_ animated: Bool) {
                                super.viewWillAppear(animated)
                                (navigationItem.leftBarButtonItem?.customView as? UIButton)?.setImage(UIImage(named: "btn_back")?.withTintColor(.white), for: .normal)
                }
 
                required init(items:[CourseItemModel],selectIndex:IndexPath) {
                                super.init(nibName: nil, bundle: nil)
                                self.items = items
                                self.selectIndex = selectIndex
                }
                
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        let item = items[selectIndex.row]
 
        guard secondLook > 0 else {return}
        Services.watchClouse(chapterId: item.id, isOver: isOver, secondLook: secondLook).subscribe(onNext: { _ in
 
        }).disposed(by: disposeBag)
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
                                title = "课程详情"
 
        videoView = VideoView(url: items[selectIndex.row].videoUrl.jq_urlEncoded(),delegate: self)
        videoView?.player.play()
                                view_bg_video.addSubview(videoView!)
                                videoView!.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
 
                                tableView.separatorStyle = .none
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.showsVerticalScrollIndicator = false
                                if #available(iOS 15.0, *) {
                                                tableView.sectionHeaderTopPadding = 0
                                }
                                tableView.register(UINib(nibName: "CourseDetail_2_Inner_TCell", bundle: nil), forCellReuseIdentifier: "_CourseDetail_2_Inner_TCell")
    }
 
                override var preferredStatusBarStyle: UIStatusBarStyle{
                                return .lightContent
                }
}
 
extension CourseDetialVideoVC:UITableViewDataSource{
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return items.count
                }
 
                func numberOfSections(in tableView: UITableView) -> Int {
                                return 1
                }
 
                func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                                return 69.5
                }
 
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseDetail_2_Inner_TCell") as! CourseDetail_2_Inner_TCell
 
                                cell.setModel(items[indexPath.row], index: indexPath)
 
                                if items[indexPath.row].isOver == .yes{
                                                cell.btn_study.setTitle("已学习", for: .normal)
                                                cell.btn_study.backgroundColor = UIColor(hexString: "#CDCDCD")
                                }else{
                                                cell.btn_study.setTitle("去学习", for: .normal)
                                                cell.btn_study.backgroundColor = UIColor(hexString: "#8AAE65")
                                }
 
                                if indexPath.row == selectIndex.row{
                                                cell.btn_study.setTitle("正在学习", for: .normal)
                                                cell.btn_study.backgroundColor = UIColor(hexString: "#E3B25C")
                                }
                                return cell
                }
}
 
extension CourseDetialVideoVC:UITableViewDelegate{
 
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
 
                                if selectIndex == indexPath{return}
 
                                selectIndex = indexPath
        videoView?.updateVideoUrl(items[indexPath.row].videoUrl.jq_urlEncoded())
                                tableView.reloadData()
                }
}
 
extension CourseDetialVideoVC:CLPlayerDelegate{
    func player(_ player: CLPlayer, playProgressChanged value: CGFloat) {
        secondLook = player.currentDuration.int
        print("视频播放进度:\(player.currentDuration.int)")
    }
 
    func didPlayToEnd(in player: CLPlayer) {
        isOver = true
        print("视频播放进度:【完成】")
    }
}