| | |
| | | |
| | | private var id:Int? |
| | | private var model:ExerciseVideoModel? |
| | | private var detailModel:VideoDetailModel? |
| | | private var exerciseVideoDetailModel:ExerciseVideoDetailModel? |
| | | |
| | | @IBOutlet weak var label_name: UILabel! |
| | | @IBOutlet weak var label_introduce: UILabel! |
| | |
| | | @IBOutlet weak var img_introduceCover: UIImageView! |
| | | @IBOutlet weak var label_coin: UILabel! |
| | | @IBOutlet weak var cons_imgHei: NSLayoutConstraint! |
| | | private var timeDuration:Double = 0 |
| | | |
| | | |
| | | private lazy var playerVC:AVPlayerViewController = { |
| | |
| | | if let id { |
| | | Services.benefitsVideoDetail(id: id).subscribe(onNext: { [weak self] data in |
| | | if let model = data.data{ |
| | | self?.detailModel = model |
| | | self?.playerVC.player = AVPlayer(url: URL(string: model.courseVideo)!) |
| | | self?.playerVC.player?.play() |
| | | |
| | | self?.playerVC.player?.addPeriodicTimeObserver(forInterval: CMTimeMake(value: 1, timescale: 1), queue: DispatchQueue.main) { [weak self](time) in |
| | | self?.timeDuration += 1 |
| | | } |
| | | |
| | | self?.label_name.text = model.name |
| | | self?.label_coin.text = "\(model.integral)积分" |
| | |
| | | if let model{ |
| | | Services.exerciseCourseDetail(coursePackageId: model.coursePackageId, videoId: model.videoId).subscribe(onNext: {[weak self] data in |
| | | if let model = data.data{ |
| | | self?.exerciseVideoDetailModel = model |
| | | self?.playerVC.player = AVPlayer(url: URL(string: model.videoURL)!) |
| | | self?.playerVC.player?.play() |
| | | |
| | | self?.playerVC.player?.addPeriodicTimeObserver(forInterval: CMTimeMake(value: 1, timescale: 1), queue: DispatchQueue.main) { [weak self](time) in |
| | | self?.timeDuration += 1 |
| | | } |
| | | |
| | | self?.label_name.text = model.packageName |
| | | self?.label_coin.text = "\(model.integral)积分" |
| | |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | NotificationCenter.default.addObserver(self, selector: #selector(playbackEnd), name:NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil) |
| | | |
| | | } |
| | | |
| | | override func setUI() { |
| | |
| | | playerVC.didMove(toParent: self) |
| | | |
| | | } |
| | | |
| | | @objc private func playbackEnd(){ |
| | | if let m = exerciseVideoDetailModel{ |
| | | if timeDuration >= CMTimeGetSeconds((playerVC.player?.currentItem?.duration)!) && m.studyStatus == 0 { |
| | | Services.updateVideoStatus(coursePackageId: m.coursePackageId, videoId: m.videoId).subscribe(onNext: {[weak self] data in |
| | | alertSuccess(msg: "已获得积分") |
| | | self?.exerciseVideoDetailModel?.studyStatus = 1 |
| | | self?.label_studyState.text = "已学习" |
| | | self?.label_studyState.backgroundColor = UIColor(hexStr: "#318C10").withAlphaComponent(0.29) |
| | | self?.label_studyState.textColor = UIColor(hexStr: "#318C10") |
| | | self?.timeDuration = 0 |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |
| | | |
| | | |
| | | if let m = detailModel{ |
| | | if timeDuration >= CMTimeGetSeconds((playerVC.player?.currentItem?.duration)!) && m.study == 0 { |
| | | Services.receiveAward(id: m.id).subscribe(onNext: {[weak self] data in |
| | | alertSuccess(msg: "已获得积分") |
| | | self?.detailModel?.study = 1 |
| | | self?.label_studyState.text = "已学习" |
| | | self?.label_studyState.backgroundColor = UIColor(hexStr: "#318C10").withAlphaComponent(0.29) |
| | | self?.label_studyState.textColor = UIColor(hexStr: "#318C10") |
| | | self?.timeDuration = 0 |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |