CNLiveShortVideoViewController.swift 47.4 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 1108 1109 1110 1111 1112 1113
//
//  CNLiveVideoViewController.swift
//  metaCode
//
//  Created by open on 2024/1/5.
//

import Foundation
import ZFPlayer
import APButton
import EmptyDataSet_Swift
import MJRefresh
import CNLiveBusinessTools
import CNLiveShareToolKit
import CNLivePayCostModule


class CNLiveShortVideoViewController : CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource, CNLiveShortVideoListTableViewCellDelegate, EmptyDataSetSource, EmptyDataSetDelegate, UICollectionViewDelegate, UICollectionViewDataSource {
    
    var player: ZFPlayerController!
    //热榜    
    lazy var hotListView :UIView = {
        let hotListView = UIView(frame: CGRect(x: 0, y: -DownSlideRealHotListDetaiH, width: KSreenWidth, height: DownSlideRealHotListDetaiH))
        return hotListView
    }()
    lazy var hotListImgView :UIImageView = {
        let hotListImgView = UIImageView(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: DownSlideRealHotListDetaiImgH))
        hotListImgView.contentMode = .scaleAspectFill
        hotListImgView.clipsToBounds = true
        return hotListImgView
    }()
    lazy var totalHotListBtn: UIButton = {
        let  totalHotListBtn = UIButton(type: .custom)
        totalHotListBtn.frame = CGRect(x: KSreenWidth-110, y: 0, width: 100, height: 50)
        totalHotListBtn.bottom = self.realHotCollectionView.top - 5
        totalHotListBtn.setTitle("完整榜单", for: .normal)
        totalHotListBtn.setTitleColor(.white, for: .normal)
        totalHotListBtn.isHidden = true
        totalHotListBtn.addTarget(self, action: #selector(totalHotListBtnAction), for: .touchUpInside)
        return totalHotListBtn
    }()

    //实时热榜的列表
    lazy var realHotArr: NSMutableArray = {
        var realHotArr = NSMutableArray()
        return realHotArr
    }()
    //实时热榜所有短剧第一集的列表
    lazy var realHotAllFirstArr: NSMutableArray = {
        var realHotArr = NSMutableArray()
        return realHotArr
    }()
    //实时热榜所有短剧全部集数的列表
    lazy var realHotAllTotalArr: NSMutableArray = {
        var realHotArr = NSMutableArray()
        return realHotArr
    }()
    //实时热榜所有短剧全部集数videoUrl的列表
    lazy var realHotAllTotalVideoUrlArr: NSMutableArray = {
        var realHotArr = NSMutableArray()
        return realHotArr
    }()
    //实时热榜所有短剧第一集videoUrl的列表
    lazy var realHotAllFirstVideoUrlArr: NSMutableArray = {
        var realHotArr = NSMutableArray()
        return realHotArr
    }()
    
    let kRealHotListCollectionViewCellIdentifier = "kRealHotListCollectionViewCellIdentifier"
    lazy var realHotCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSizeMake(69, 100+24)
        layout.sectionInset = .init(top: 0, left: DownSlideRecommendLeftGap, bottom: 0, right: 0)
        layout.minimumLineSpacing = 6
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.delegate = self
        cv.dataSource = self
        cv.backgroundColor = .white
        cv.layer.cornerRadius = 12
        cv.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
        cv.register(CNLiveDownSlideRealHotListCell.self, forCellWithReuseIdentifier: kRealHotListCollectionViewCellIdentifier)
        return cv
    }()
    
    let kVideoBodyListViewCellIdentifier = "kVideoBodyListViewCellIdentifier"
    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.emptyDataSetSource = self
        tableView.emptyDataSetDelegate = self
        tableView.isPagingEnabled = true
        tableView.estimatedRowHeight = 0
        tableView.estimatedSectionFooterHeight = 0
        tableView.estimatedSectionHeaderHeight = 0
        tableView.frame = view.bounds
        tableView.rowHeight = tableView.frame.size.height
        tableView.backgroundColor = .black
        tableView.tableFooterView = UIView.init()
        tableView.separatorStyle = .none
        tableView.scrollsToTop = false
        if #available(iOS 11.0, *) {
            tableView.contentInsetAdjustmentBehavior = .never;
        } else {
            self.automaticallyAdjustsScrollViewInsets = false;
        }
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
        tableView.register(CNLiveShortVideoListTableViewCell.self, forCellReuseIdentifier: kVideoBodyListViewCellIdentifier)
        return tableView
    }()
    
    lazy var backBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.setImage(UIImage(named: "short_video_close"), for: .normal)
        button.addTarget(self, action: #selector(backClick(_:)), for: .touchUpInside)
        return button
    }()
    lazy var hotListBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = HexColor("#000000", alpha: 0.3)
        button.setTitle("上滑查看完整视频", for: .normal)
        button.setTitle("查看实时热榜", for: .selected)
        button.setTitleColor(.white, for: .normal)
        button.titleLabel?.font = Font_13
        button.layer.cornerRadius = 14
        button.clipsToBounds = true
        button.addTarget(self, action: #selector(hotListBtnClick(_:)), for: .touchUpInside)
        return button
    }()
    
    
    lazy var controlView: CNLiveShortVideoControlView = {
        let controlView = CNLiveShortVideoControlView.init(frame: CGRectZero)
        return controlView
    }()
    
    lazy var headerRefreshView: UIRefreshControl = {
        let headerRefreshView = UIRefreshControl()
        headerRefreshView.tintColor = .white
        headerRefreshView.addTarget(self, action: #selector(headerRefresh), for: .valueChanged)
        return headerRefreshView
    }()
    
    lazy var dataArray: NSMutableArray = {
        let dataArray = NSMutableArray.init()
        return dataArray
    }()
    lazy var dataURLArray: NSMutableArray = {
        let dataArray = NSMutableArray.init()
        return dataArray
    }()
    

    var aid: String! = ""
    var pageNum: NSInteger! = 1//页数
    var slideModel:CNLiveDownSlideModel?
    var isSelectable: Bool! = false
    var currentIndex: NSInteger! = 0//播放集数
    var pickerView: CNLiveShortVideoContentListView!
    var footerRefreshView: CNLiveFooterRefresh!
//    var playerManager = ZFIJKPlayerManager.init()
    var playerManager = ZFAVPlayerManager.init()
    var previousOffset:CGFloat = 50000.0
    
    
    let group = DispatchGroup()
    let queue = DispatchQueue.global(qos: .default)
    var currentDuanJuIndex: NSInteger! = 0//播放短剧index
    var isDuanJuPlayer = false//是否 短剧播放器
    var isTempDuanJuPlayer = false//临时是否 短剧播放器
    var isPausePlayer = false//是否暂停播放
    var isHomePagePush = false//是否 主页Push
    lazy var tempDataArray: NSMutableArray = {//临时剧集
        let dataArray = NSMutableArray.init()
        return dataArray
    }()
    lazy var tempDataURLArray: NSMutableArray = {//临时剧集url
        let dataArray = NSMutableArray.init()
        return dataArray
    }()
    
    /// 初始化播放器
    /// - Parameters:
    ///   - aid: 专辑 id
    ///   - page: 当前页数
    ///   - currentIndex: 当前点击的索引
    ///   - dataArray: 当前请求的数据
    init(aid: String,page: NSInteger, currentIndex: NSInteger, dataArray: [CNLiveAlbumListModel]) {
        self.aid = aid
        self.pageNum = page
        self.isSelectable = true
        self.currentIndex = currentIndex
        self.isHomePagePush = true
        super.init(nibName:nil, bundle:nil)
        self.dataArray.addObjects(from: dataArray)
        dataArray.forEach {[weak self] listModel in
            guard let self = self else { return }
            self.dataURLArray.add(listModel.videoUrl)
        }
        self.tempDataArray.addObjects(from: dataArray)
        self.tempDataURLArray.addObjects(from: self.dataURLArray as! [Any])
    }
    
    /// 初始化播放器
    /// - Parameter aid: 专辑 id
    init(aid: String) {
        self.aid = aid
        self.isSelectable = false
        super.init(nibName:nil, bundle:nil)
    }
    
    /// 初始化播放器,第多少集
    /// - Parameter aid: 专辑 id ,第多少集
    init(aid: String,currentIndex: NSInteger,slideModel:CNLiveDownSlideModel?) {
        self.aid = aid
        self.isSelectable = false
        self.currentIndex = currentIndex
        
        if let mdl = slideModel{
            self.isDuanJuPlayer = true
            for (idx,model) in mdl.contents.enumerated() {
                if model.contentId == aid{
                    self.currentDuanJuIndex = idx
                    break
                }
            }
        }
        
        super.init(nibName:nil, bundle:nil)
        self.slideModel = slideModel
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if self.dataArray.count > 0 && self.isSelectable {
            self.playTheIndex(index: self.currentIndex)
        }
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.player.currentPlayerManager.play()
        if self.isDuanJuPlayer{
            
        }else{
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
                self.player.scrollView?.setContentOffset(CGPoint(x: 0, y:CGFloat(self.currentIndex!)*KSreenHeight), animated: false)//校正偏移量
            }
        }
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.player.currentPlayerManager.pause()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .black
        view.addSubview(tableView)

        if self.slideModel != nil{
            view.addSubview(hotListView)
            hotListView.addSubview(self.hotListImgView)
            self.hotListImgView.kf.setImage(with: URL(string: self.slideModel!.blockIcon))
            hotListView.addSubview(self.realHotCollectionView)
            view.addSubview(hotListBtn)
            self.realHotCollectionView.frame = CGRect(x: 0, y: DownSlideRealHotListDetaiH-DownSlideRealHotListDetaiCollectCellH, width: KSreenWidth, height: DownSlideRealHotListDetaiCollectCellH)
            self.realHotArr = NSMutableArray(array: self.slideModel!.contents)
            self.realHotCollectionView.reloadData()
            self.updateHotListView(isShow: self.slideModel == nil ? false : true)
            view.addSubview(self.totalHotListBtn)
            self.totalHotListBtn.isHidden = false
            
            self.requestAllHotListData { noMore in
                
            }
        }else{
            if self.dataArray.count == 0 {
                requestData {noMore in }
            }
        }
        
        view.addSubview(backBtn)
        

        addRefreshView()
        if self.tableView.mj_footer == nil  {
            self.tableView.mj_footer = footerRefreshView
        }

        player = ZFPlayerController(scrollView: tableView, playerManager: playerManager, containerViewTag: 100)
        player.disableGestureTypes = [.pan, .pinch]
        player.disablePanMovingDirection = .vertical
        player.controlView = controlView
        player.allowOrentitaionRotation = false
        player.isWWANAutoPlay = true
        player.playerDisapperaPercent = 1.0
        player.scrollView?.isPagingEnabled = true
        player.playerReadyToPlay = {[weak self] asset, assetURL in
            guard let self = self else { return }
            self.controlView.videoPlayer((self.player)!, currentTime: self.player.currentTime, totalTime: self.player.totalTime)
            
            let index = self.dataURLArray.index(of: assetURL.absoluteString)
            if index < 10000{//防止出现取不到值,为int最大值情况
                if let homeModel = self.dataArray[index] as? CNLiveAlbumListModel{
                    self.currentIndex = index
                    if homeModel.product?.check == false {
                        if homeModel.product?.productType == "4" {
                            //这里表示可以进行试听
                        } else {
                            (self.player)!.stopCurrentPlayingCell()
                        }
                    }
                }else{
                    
                }
            }
        }
        // 更新另一个控制层的时间
        player.playerPlayTimeChanged = { [weak self] asset, currentTime, duration in
            guard let self = self else { return }
            self.controlView.videoPlayer((self.player)!, currentTime: currentTime, totalTime: duration)
        }
        // 更新另一个控制层的缓冲时间
        player.playerBufferTimeChanged = { [weak self] asset, bufferTime in
            guard let self = self else { return }
            self.controlView.videoPlayer((self.player)!, bufferTime: bufferTime)
        }
        // 停止的时候找出最合适的播放
        player.zf_scrollViewDidEndScrollingCallback = { [weak self] indexPath in
            guard let self = self else { return }
            if self.player.playingIndexPath != nil {
                return
            }
            self.playVideo(at: indexPath)
        }
        player.playerDidToEnd = {[weak self] asset in
            guard let self = self else { return }
            self.controlView.videoPlayer((self.player)!)
            self.player.currentPlayerManager.stop()
            //短剧播放器->剧集播放器  播放下一集
            self.currentIndex = self.currentIndex + 1
            if self.currentIndex >= self.dataArray.count{
                //最后一集,重置为最后一集
                self.currentIndex = self.dataArray.count - 1
            }
            
            let indexPath = IndexPath(row: self.currentIndex, section: 0)
            self.player.scrollView?.setContentOffset(CGPoint(x: 0, y:CGFloat(self.currentIndex)*KSreenHeight), animated: false)//校正偏移量
            self.playVideo(at: indexPath as IndexPath)
            //开始播放调用recordApi/end
            let data: CNLiveAlbumListModel = dataArray[indexPath.row] as! CNLiveAlbumListModel
            CNLiveShortVideoViewModel.requestAudioPlayRecordEnd(contentId: data.contentId, channelName: data.title)
        }
        
        NotificationCenter.default.addObserver(self, selector: #selector(removePlayerAction), name: Notification.Name.PlayerManage.kPlayerDestroyNotification, object: nil)
    }
    
    func updateHotListView(isShow:Bool){
        if let model = self.slideModel{
            if isShow{//展示热榜
                UIView.animate(withDuration: 0.25) {
                    self.hotListView.top = 0
                    self.tableView.top = self.hotListView.bottom
                }
                self.hotListBtn.isSelected = false
                self.totalHotListBtn.isHidden = false
            }else{
                //隐藏热榜
                UIView.animate(withDuration: 0.25) {
                    self.hotListView.top = -self.hotListView.height
                    self.tableView.top = self.hotListView.bottom
                }
                self.hotListBtn.isSelected = true
                self.totalHotListBtn.isHidden = true
            }
        }else{
            //隐藏热榜
            UIView.animate(withDuration: 0.25) {
                self.hotListView.top = -self.hotListView.height
                self.tableView.top = self.hotListView.bottom
            }
            self.hotListBtn.isSelected = true
            self.totalHotListBtn.isHidden = true
        }
    }
    
    // MARK: - 实时热榜里横向列表
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        self.realHotArr.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kRealHotListCollectionViewCellIdentifier, for: indexPath) as! CNLiveDownSlideRealHotListCell
        cell.num = indexPath.row+1
        // 加载和设置图片到 cell.imageView
        cell.contentsModel = self.realHotArr[indexPath.row] as? CNLiveDownSlideContentsModel
        return cell

    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if let contentMdl = self.realHotArr[indexPath.row] as? CNLiveDownSlideContentsModel{
            //在当前堆栈里遍历删除 播放控制器CNLiveShortVideoViewController
            let tempArray = NSMutableArray.init()
            self.navigationController?.viewControllers.forEach({ item in
                if (item.isKind(of: CNLiveShortVideoViewController.self)) {
                    tempArray.remove(item)
                }else{
                    tempArray.add(item)
                }
            })
            self.navigationController?.viewControllers = tempArray as! [CNLiveBaseViewController]
            //实时热榜点击短剧
            CNLiveDownSlideTool.pushWebVCWithContentsMdl(model: contentMdl.model , contentId: contentMdl.contentId , pid: contentMdl.pid , shareUrl: contentMdl.shareUrl , thirdUrl: contentMdl.thirdUrl , title: contentMdl.title , s_to: contentMdl.s_to ,trailerId: contentMdl.trailerId , controller: nil, slideModel: self.slideModel)
        }
    }
    
    func addRefreshView() {
        self.tableView.refreshControl = headerRefreshView
        footerRefreshView = CNLiveFooterRefresh(refreshingBlock: { [weak self] in
            guard let self = self else { return }
            if self.isDuanJuPlayer
            {//短剧
                if self.tableView.mj_footer != nil {
                    self.tableView.mj_footer?.endRefreshing()
                    self.tableView.mj_footer?.endRefreshingWithNoMoreData()
                }
            }else{//剧集
                self.player.stopCurrentPlayingCell()
                self.pageNum += 1
                self.requestData {noMore in }
            }
        })
        //预加载下
        CNLiveQQEmotionManager.emotionsForQQ()
    }
    
    @objc func headerRefresh() {
        self.pageNum = 1
        if self.isDuanJuPlayer{
            self.requestAllHotListData { noMore in }
        }else{
            self.realHotArr.removeAllObjects()
            self.realHotAllFirstArr.removeAllObjects()
            self.realHotAllTotalArr.removeAllObjects()
            self.realHotAllTotalVideoUrlArr.removeAllObjects()
            self.currentDuanJuIndex = 0
            self.isHomePagePush = false
            self.currentIndex = 0
            self.currentDuanJuIndex = 0
            if self.pickerView != nil {
                self.pickerView.setupWithArray(dataArray: self.dataArray)
            }
            self.tableView.refreshControl?.endRefreshing()
            self.tableView.reloadData()
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                self.player.scrollView?.setContentOffset(CGPoint(x: 0, y:CGFloat(self.currentIndex!)*KSreenHeight), animated: false)//校正偏移量
            }
        }
    }
    
    @objc func removePlayerAction() {
        controlView.removeFromSuperview()
        if player != nil {
            player.stopCurrentPlayingCell()
        }
//        if (playerManager.player != nil) {
//            playerManager.player.stop()
//            playerManager.avPlayerLayer.removeFromSuperlayer()
//        }
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        self.backBtn.frame = CGRectMake(15, KStatusBarHeight + 5, 45, 45)
        self.hotListBtn.frame = CGRectMake((KSreenWidth-144)/2.0, self.hotListView.bottom+19, 144, 28)
    }
    
    // MARK: - 请求实时热榜的所有短剧,全部集数数据
    func requestAllHotListData(resultBlock: @escaping (_ noMore: Bool) -> Void) {
        self.realHotAllFirstArr.removeAllObjects()
        self.realHotAllTotalArr.removeAllObjects()
        self.dataArray.removeAllObjects()
        self.dataURLArray.removeAllObjects()
        self.tempDataArray.removeAllObjects()
        self.tempDataURLArray.removeAllObjects()

        showLoading(message: "")
        let tempRealHotArr = Array(self.realHotArr)
        tempRealHotArr.forEach { contMdl in
            if let contentsModel = contMdl as? CNLiveDownSlideContentsModel{
                self.group.enter()
                
                CNLiveShortVideoViewModel.requstWithShortVideo(aid: contentsModel.contentId, page: 1, pageSize: "10") { [weak self] result, respStatue in
                    guard let self = self else { return }
                    if respStatue == .success {
                        
                        let listArray = (result as! [Any]).first as! [CNLiveAlbumListModel]
                        
                        self.realHotAllTotalArr.add(listArray)
                        let urlArray = (result as! [Any]).last as! [String]
                        self.realHotAllTotalVideoUrlArr.add(urlArray)
                        
                        self.group.leave()
                    } else {
//                        if self.tableView.mj_footer != nil {
//                            self.tableView.mj_footer?.endRefreshing()
//                        }
//                        self.tableView.contentOffset = CGPoint.zero
//                        self.tableView.refreshControl?.endRefreshing()
//                        if self.dataArray.count == 0 {
//                            self.tableView.reloadEmptyDataSet()
//                        }
                        
                        
                        self.group.leave()
                    }
                }
            }
                
        }
        
        
        self.group.notify(queue: .main) {
            // 所有网络请求都已完成,在这里执行你的任务
            
            var aidToModelIndex: [String : Int] = [:]
            for (index, arr) in self.realHotAllTotalArr.enumerated() {
                let juArr = arr as! [CNLiveAlbumListModel]
                if juArr.count > 0{
                    let model = juArr.first
                    let albumId = model!.albumMsgModel!.albumId
                    aidToModelIndex[albumId] = index
                }
            }
            let sortedModels = NSMutableArray()
            let sortedUrlModels = NSMutableArray()
            for contMdl in self.realHotArr {
                let model = contMdl as! CNLiveDownSlideContentsModel
                if let index = aidToModelIndex[model.contentId] {
                    sortedModels.add(self.realHotAllTotalArr[index] as! [CNLiveAlbumListModel])
                    sortedUrlModels.add(self.realHotAllTotalVideoUrlArr[index] as! [String])
//                    if self.aid == model.contentId{
//                        self.currentDuanJuIndex = index
//                    }
                }
                
            }
            self.realHotAllTotalArr = NSMutableArray(array: sortedModels)
            self.realHotAllTotalVideoUrlArr = NSMutableArray(array: sortedUrlModels)
            
            self.realHotAllTotalArr.forEach { arr in
                let juArr = arr as! [CNLiveAlbumListModel]
                if juArr.count > 0{
                    let model = juArr.first
                    self.realHotAllFirstArr.add(model!)
                }
            }
            
            self.realHotAllTotalVideoUrlArr.forEach{ arr in
                let urlArr = arr as! [String]
                if urlArr.count > 0{
                    let url = urlArr.first
                    self.realHotAllFirstVideoUrlArr.add(url!)
                }
            }
            
            //等全部数据弄好了再设置
            self.dataArray.addObjects(from: self.realHotAllFirstArr as! [CNLiveAlbumListModel])
            self.dataURLArray.addObjects(from: self.realHotAllFirstVideoUrlArr as! [String])
            //
            self.tempDataArray.addObjects(from: self.realHotAllTotalArr[self.currentDuanJuIndex] as! [CNLiveAlbumListModel])
            self.tempDataURLArray.addObjects(from: self.realHotAllTotalVideoUrlArr[self.currentDuanJuIndex] as! [String])
            if self.tableView.mj_footer != nil {
                self.tableView.mj_footer?.endRefreshing()
            }
            if self.pickerView != nil {
                let arr = self.realHotAllTotalArr[self.currentDuanJuIndex] as! NSMutableArray
                self.pickerView.setupWithArray(dataArray: arr)
            }
            self.tableView.refreshControl?.endRefreshing()
            self.tableView.reloadData()

            if self.tableView.mj_footer == nil  {
                self.tableView.mj_footer = self.footerRefreshView
            }
            
            self.playTheIndex(index: self.currentDuanJuIndex)
        }
        
    }
    
    //请求一个短剧的全部集数数据
    func requestData(resultBlock: @escaping (_ noMore: Bool) -> Void) {
        CNLiveShortVideoViewModel.requstWithShortVideo(aid: self.aid, page: self.pageNum, pageSize: "10") { [weak self] result, respStatue in
            guard let self = self else { return }
            if respStatue == .success {
                if self.pageNum == 1 {
                    self.dataArray.removeAllObjects()
                    self.dataURLArray.removeAllObjects()
                }
                var listArray = [CNLiveAlbumListModel]()
                var urlArray = [String]()
                if self.isTempDuanJuPlayer{
                    //是短剧,点击了集数列表
                    if self.isDuanJuPlayer{
                        //没点集数,还是短剧
                        print("1")
                    }else{
                        //点击了集数,切换剧集
                        listArray = (result as! [Any]).first as! [CNLiveAlbumListModel]
                        self.tempDataArray.addObjects(from: listArray)
                        urlArray = (result as! [Any]).last as! [String]
                        self.tempDataURLArray.addObjects(from: urlArray)
                        self.dataArray.removeAllObjects()
                        self.dataArray.addObjects(from: self.tempDataArray as! [Any])
                        self.dataURLArray.removeAllObjects()
                        self.dataURLArray.addObjects(from: self.tempDataURLArray as! [Any])
                    }
                }else{
                    //剧集
                    listArray = (result as! [Any]).first as! [CNLiveAlbumListModel]
                    self.tempDataArray.addObjects(from: listArray)
                    urlArray = (result as! [Any]).last as! [String]
                    self.tempDataURLArray.addObjects(from: urlArray)
                    self.dataArray.removeAllObjects()
                    self.dataArray.addObjects(from: self.tempDataArray as! [Any])
                    self.dataURLArray.removeAllObjects()
                    self.dataURLArray.addObjects(from: self.tempDataURLArray as! [Any])
                }
                if self.tableView.mj_footer != nil {
                    self.tableView.mj_footer?.endRefreshing()
                }
                if self.pickerView != nil {
                    self.pickerView.setupWithArray(dataArray: self.dataArray)
                }
                self.tableView.refreshControl?.endRefreshing()
                self.tableView.reloadData()

                let hasNextPage = (result as! [Any])[1] as! Bool
                if listArray.count == 0 && urlArray.count == 0 {
                    if !hasNextPage {
                        self.tableView.mj_footer?.endRefreshingWithNoMoreData()
                        self.tableView.reloadData()
                        resultBlock(true)
                    }
                } else {
                    resultBlock(false)
                    if self.tableView.mj_footer == nil  {
                        self.tableView.mj_footer = footerRefreshView
                    }
                }
                
                if self.isTempDuanJuPlayer == true && self.isDuanJuPlayer == false{
                    //从短剧变为剧集
//                    self.playTheIndex(index: self.currentIndex)
                }else{//剧集
                    if self.slideModel == nil && self.currentIndex == 0{//非实时热榜进入,找上一次播放集数
                        let model = listArray.first?.albumMsgModel
                        let toIndex = (model?.episodeLast ?? 1)-1 <= 0 ? 0 : (model?.episodeLast ?? 1)-1
                        var page = (self.roundUpToNearestTen(toIndex))/10
                        if page == 0 {
                            page = 1
                        }
                        self.pageNum = page
                        self.playTheIndex(index: toIndex)
                    }else{
                        print("加载更多列表")
                    }
                }
            } else {
                if self.tableView.mj_footer != nil {
                    self.tableView.mj_footer?.endRefreshing()
                }
                self.tableView.contentOffset = CGPoint.zero
                self.tableView.refreshControl?.endRefreshing()
                if self.dataArray.count == 0 {
                    self.tableView.reloadEmptyDataSet()
                }
            }
        }
    }
    
    open func playTheIndex(index: NSInteger) {
        // 指定到某一行播放
        let indexPath = IndexPath(row: index, section: 0)
        tableView.scrollToRow(at: indexPath, at: .none, animated: false)
//        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
//            self.player.scrollView?.setContentOffset(CGPoint(x: 0, y:CGFloat(index)*KSreenHeight), animated: false)//校正偏移量
//            self.playVideo(at: IndexPath(row: index, section: 0))
//        }

        // 使用zf_filterShouldPlayCellWhileScrolled过滤播放
        self.player.zf_filterShouldPlayCellWhileScrolled { [weak self] indexPath in
            guard let self = self else { return }
            self.playVideo(at: indexPath)
        }
        
        //隐藏实时热榜view
        self.hotListBtn.isHidden = !self.isDuanJuPlayer
    }

    override var shouldAutorotate: Bool {
        return false
    }

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

    override var prefersStatusBarHidden: Bool {
        return false
    }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .allButUpsideDown
    }
    
    @objc func backClick(_ sender: UIButton) {
        self.navigationController?.popViewController(animated: true)
    }
    @objc func hotListBtnClick(_ sender: UIButton) {
        if sender.isSelected == false{
            //隐藏热榜
            self.updateHotListView(isShow: false)
        }else{
            //查看热榜
            self.updateHotListView(isShow: true)
        }
    }
    @objc func totalHotListBtnAction(_ sender: UIButton) {
        //在当前堆栈里遍历删除 播放控制器CNLiveShortVideoViewController
        let tempArray = NSMutableArray.init()
        self.navigationController?.viewControllers.forEach({ item in
            if (item.isKind(of: CNLiveTotalHotListController.self)) {
                tempArray.remove(item)
            }else{
                tempArray.add(item)
            }
        })
        self.navigationController?.viewControllers = tempArray as! [CNLiveBaseViewController]
        self.navigationController?.pushViewController(CNLiveTotalHotListController(slideModel: self.slideModel), animated: true)
    }
    
    
    func playVideo(at indexPath: IndexPath) {
        
        if self.isDuanJuPlayer{
            self.currentDuanJuIndex = indexPath.row
            if self.currentDuanJuIndex < self.realHotAllTotalArr.count{
                let arr1 = self.realHotAllTotalArr[self.currentDuanJuIndex] as! Array<Any>
                let arr = NSMutableArray()
                arr1.forEach { obj in
                    let duanjuMdl = obj as! CNLiveAlbumListModel
                    arr.add(duanjuMdl)
                }
                if self.pickerView != nil {
                    self.pickerView.setupWithArray(dataArray: arr)
                }
            }
        }else{
            if self.pickerView != nil {
                self.pickerView.setupWithArray(dataArray: self.dataArray)
            }
        }
        if self.isPausePlayer == true{
//            self.playerManager.pause()
            print("111")
        }else{
            var index = 0
            if self.isHomePagePush == true{
                //是主页push
                self.isHomePagePush = false
                index = self.currentIndex
            }else{
                //不是主页push
                self.currentIndex = indexPath.row
                index = self.currentIndex
                
            }
            let idxPath = IndexPath(row: index, section: indexPath.section)
            if let data: CNLiveAlbumListModel = dataArray[index] as? CNLiveAlbumListModel{
                self.player.playTheIndexPath(idxPath, assetURL: URL(string: data.videoUrl)!)
                controlView.resetControlView()
                controlView.showCoverView(withUrl: data.poster)
            }
        }
    }
    //10倍数向上取整
    func roundUpToNearestTen(_ number: Int) -> Int {
        // 如果余数为0,则已经是10的倍数
        if number % 10 == 0 {
            return number
        } else {
            // 否则,向上取整到最近的10的倍数
            // 可以通过除以10,向上取整,然后再乘以10来得到结果
            return ((number + 9) / 10) * 10
        }
    }
    
    
//    /// 横竖屏旋转监听
//    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
//        super.traitCollectionDidChange(previousTraitCollection)
//        if traitCollection.verticalSizeClass != previousTraitCollection?.verticalSizeClass {
//            // 横竖屏UI适配
//            if UIDevice.current.orientation.isCurrentScreenPortrait() {
//                //竖屏布局
//                
//            } else {
//                //横屏布局
//                print("横屏")
//                
//            }
//        }
//    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
        tableView.delegate = nil
        tableView.dataSource = nil
        controlView.removeFromSuperview()
        player.stopCurrentPlayingCell()
//        if (playerManager.player != nil) {
//            playerManager.player.stop()
//            playerManager.avPlayerLayer.removeFromSuperlayer()
//        }
        print("销毁了")
    }
}
extension CNLiveShortVideoViewController {
    
    func likeActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
        CNLiveShortVideoViewModel.requestRankWithLike(contentId: viewcell.homeModel.pid, contentTitle: viewcell.homeModel.title, contentSid: viewcell.homeModel.icon!.id, support: viewcell.homeModel.tool!.liked, isShare: false) {result, respStatue in
            if respStatue == .success {
                viewcell.homeModel.tool!.liked = !viewcell.homeModel.tool!.liked
                if viewcell.homeModel.tool!.liked {
                    viewcell.homeModel.tool?.likesNum = "\(Int(viewcell.homeModel.tool!.likesNum)! + 1)"
                } else {
                    viewcell.homeModel.tool?.likesNum = "\(Int(viewcell.homeModel.tool!.likesNum)! - 1)"
                }
                button.setTitle(viewcell.homeModel.tool?.likesNum, for: .normal)
                button.isSelected = viewcell.homeModel.tool!.liked
            }
        }
    }
    func commentActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
        CNLiveShortVideoCommentListView.showVideoCommentListView(pid: viewcell.homeModel.pid, contentSid: viewcell.homeModel.icon!.id, result: { commentModel in
            button.setTitle("\(commentModel)", for: .normal)
        })
    }
    func shareActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
        CNLiveShareManager.showShareViewWithParam(forShareTitle: viewcell.homeModel.title, shareUrl: viewcell.homeModel.shareUrl, shareDesc: viewcell.homeModel.subTitle, shareImage: viewcell.homeModel.poster, screenFull: false, hiddenWjj: true, hiddenQQ: false, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: true, formVC: self, topImage: [], topTitles: [], platformType: .all) { title in} completerBlock: {resultType, platformType, typeString in
            if resultType == .succ {
                showLoading(message: "")
                CNLiveShortVideoViewModel.requestRankWithLike(contentId: viewcell.homeModel.pid, contentTitle: viewcell.homeModel.title, contentSid: viewcell.homeModel.icon!.id, support: true, isShare: true) {result, respStatue in
                    if respStatue == .success {
                            viewcell.homeModel.tool?.shareNum = "\(Int(viewcell.homeModel.tool!.shareNum)! + 1)"
                        button.setTitle(viewcell.homeModel.tool?.shareNum, for: .normal)
                    }
                }
            }
        }
    }
    func iconActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
        self.navigationController?.pushViewController(CNLivePlayletHomePageController(aid: aid), animated: true)
    }
    func faviActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: APButton) {
        button.startAnimating()
        CNLiveShortVideoViewModel.requestCollect(aid: aid, type: viewcell.homeModel.tool!.collectioned) { result, respStatue in
            if respStatue == .success {
                showMessage(message: result as! String)
                viewcell.homeModel.tool!.collectioned = !viewcell.homeModel.tool!.collectioned
                DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                    button.isHidden = true
                }
            }
        }
    }
    func listActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
        let arr = NSMutableArray()
        var pageNum:NSInteger = 1
        if self.isDuanJuPlayer{
            let listArr =   self.realHotAllTotalArr[self.currentDuanJuIndex] as! [CNLiveAlbumListModel]
            arr.addObjects(from: listArr)
            pageNum = 1
            self.aid = listArr.first?.albumMsgModel?.albumId
            self.tempDataArray.removeAllObjects()
            self.tempDataArray.addObjects(from: self.realHotAllTotalArr[self.currentDuanJuIndex] as! [CNLiveAlbumListModel])
            self.tempDataURLArray.removeAllObjects()
            self.tempDataURLArray.addObjects(from: self.realHotAllTotalVideoUrlArr[self.currentDuanJuIndex] as! [String])
        }else{
            arr.addObjects(from: self.dataArray as! [Any])
            pageNum = self.pageNum
        }
        
        self.isTempDuanJuPlayer = self.isDuanJuPlayer
        self.isDuanJuPlayer = false
        self.isPausePlayer = true
        
        pickerView = CNLiveShortVideoContentListView.showVideoContentListView(aid: viewcell.homeModel.albumMsgModel!.albumId,pageNum: pageNum,title: viewcell.homeModel.albumMsgModel!.albumName,dataArray: arr, episodeNow: viewcell.homeModel.albumMsgModel!.episodeNow, result: {[weak self] listModel in
            guard let self = self else { return }
            
            if listModel is String{
                //点击了x
                self.isDuanJuPlayer = self.isTempDuanJuPlayer
                self.isPausePlayer = false
            }else{
                // MARK: - 点击了剧集列表cell
                //切换为剧集播放器
                self.isPausePlayer = false
                self.isDuanJuPlayer = false
                self.isTempDuanJuPlayer = false
                //更改数据源
                self.dataArray.removeAllObjects()
                self.dataURLArray.removeAllObjects()
                
                self.dataArray.addObjects(from: self.tempDataArray as! [CNLiveAlbumListModel])

                self.dataURLArray.addObjects(from: self.tempDataURLArray as! [String])
                
                self.tableView.reloadData()
                let index = self.dataArray.index(of: listModel) as NSInteger
                self.currentIndex = index
                self.playTheIndex(index: index)
            }
        }, reload: {[weak self] page in
            guard let self = self else { return }
            self.player.stopCurrentPlayingCell()
            if page == 1{
                self.currentIndex = 0
            }
            self.pageNum = page
            
            self.requestData { noMore in
                self.pickerView.tableView.mj_footer?.endRefreshing()
                if noMore {
                    self.pickerView.tableView.mj_footer?.endRefreshingWithNoMoreData()
                }
            }
            
        })
    }
    
    func fullScreenBtnMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
//        player.enterPortraitFullScreen(true, animated: true) {
//
//        }
//        player.rotate(to: UIInterfaceOrientation.landscapeRight, animated: true) {
//
//        }
        player.enterFullScreen(true, animated: true) {
            
        }

//        if let windowScene = view.window?.windowScene {
//            if windowScene.interfaceOrientation.isPortrait {
//                windowScene.setInterfaceOrientation(.landscapeRight)
//                // 恢复为支持所有方向
//                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
//                    let appDelegate = UIApplication.shared.delegate as! AppDelegate
//                    appDelegate.orientationLock = .all
//                }
//            } else {
//                windowScene.setInterfaceOrientation(.portrait)
//                // 恢复为支持所有方向
//                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
//                    let appDelegate = UIApplication.shared.delegate as! AppDelegate
//                    appDelegate.orientationLock = .all
//                }
//            }
//        }

    }
    
    func payActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) {
        let payButton = button as! APButton
        payButton.startAnimating()
        
        let orderId = CNLiveHomePageViewModel.getRandomOrderId()
        let notifyUrl = "http://apps.pay.cnlive.com/upappnotify/notify/orderForVideo"
        //分转元,没有小数点
        let fenString = viewcell.homeModel.albumMsgModel?.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 = viewcell.homeModel.albumMsgModel?.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 }
            payButton.stopAnimating()
            if result == CNLivePayCostTypeResultSucc{
                print("succ")
                for item in self.dataArray {
                    let homeModel = item as! CNLiveAlbumListModel
                    homeModel.product!.check = true
                    self.tableView.reloadData()
                }
                let index = self.dataArray.index(of: viewcell.homeModel as Any)
                self.playTheIndex(index: index)
            }
            
        }

        
        
//        CNLiveIntegralAlertTool.shared.showIntegralAlert(title: "\(viewcell.homeModel.albumMsgModel?.albumName ?? "")共\(viewcell.homeModel.albumMsgModel?.episodeNow ?? "1")集", integralCount: viewcell.homeModel.albumMsgModel?.product?.point ?? "0", productId: viewcell.homeModel.product?.productId ?? "")
//        CNLiveIntegralAlertTool.shared.integralStatusChangedBlock = {[weak self] integralPayStatus in
//            guard let self = self else { return }
//            payButton.stopAnimating()
//            if integralPayStatus == .paySuccess{
//                for item in self.dataArray {
//                    let homeModel = item as! CNLiveAlbumListModel
//                    homeModel.product!.check = true
//                    self.tableView.reloadData()
//                }
//                let index = self.dataArray.index(of: viewcell.homeModel as Any)
//                self.playTheIndex(index: index)
//            }
//        }
    }
}

extension CNLiveShortVideoViewController {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kVideoBodyListViewCellIdentifier) as? CNLiveShortVideoListTableViewCell else {
            return CNLiveShortVideoListTableViewCell()
        }
        cell.delegate = self
        cell.setupWithData(model: dataArray[indexPath.row] as! CNLiveAlbumListModel)
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.playVideo(at: indexPath)
    }
    
    func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
        return UIImage(named: "short_video_default")
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        scrollView.zf_scrollViewDidEndDecelerating()
    }
    
    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        scrollView.zf_scrollViewDidEndDraggingWillDecelerate(decelerate)
    }
    
    func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
        scrollView.zf_scrollViewDidScrollToTop()
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        scrollView.zf_scrollViewDidScroll()
        if previousOffset != 50000.0{
            if self.tableView.contentOffset.y < previousOffset {
                // 向下滑动
            } else if self.tableView.contentOffset.y > previousOffset {
                // 向上滑动
                self.updateHotListView(isShow: false)
                print("TableView is scrolling down")
            }
        }
        previousOffset = self.tableView.contentOffset.y
    }
    
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        scrollView.zf_scrollViewWillBeginDragging()
    }
    
    func zf_playTheVideo(at indexPath: IndexPath) {
        self.playVideo(at: indexPath)
    }
}