CNLiveDownSlideTool.swift 37.7 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
//
//  CNLiveDownSlideTool.swift
//  metaCode
//
//  Created by zx on 2023/10/25.
//  跳转

import Foundation
import CNLiveShareToolKit

typealias downSlideVodResultBlock = (_ vodPlayModel:CNLiveVodPlayModel,_ contentId:String,_ url:String,_ result: CNLiveVodAlbumListBaseModel?,_ status:CNLiveDownSlideResponseType) -> Void

//忽必烈专用电商host
let hubilieDSHost = "https://managemall.cnlive.com/html/mall/kublai/#/"
//网家家电商host
let wjjDSHost = "https://managemall.cnlive.com/html/mall/1/#/"

class CNLiveDownSlideTool:NSObject{

    class func pushWebVCWithContentsMdl(model:String,contentId:String,pid:String,shareUrl:String,thirdUrl:String,title:String,s_to:String,trailerId:String,controller:UIViewController?,slideModel:CNLiveDownSlideModel?){//contentMdl:CNLiveDownSlideContentsModel
        showLoading(message: "")
        if (model == kCNDownSlideContentsModelModel1) {
            
            let queryItem = URLQueryItem(name: "contentId", value: contentId)
            let queryItem1 = URLQueryItem(name: "videoId", value: pid)
            let urlComponents = NSURLComponents(string: shareUrl)!
            urlComponents.queryItems = [queryItem, queryItem1]
            let regURL = urlComponents.url
            let webVC = CNWebViewController()
            webVC.url = regURL
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModel2){
            
            let queryItem = URLQueryItem(name: "contentId", value: contentId)
            let queryItem1 = URLQueryItem(name: "activityId", value: pid)
            let queryItem2 = URLQueryItem(name: "pid", value: pid)
            let queryItem3 = URLQueryItem(name: "trailerId", value: trailerId)
            let urlComponents = NSURLComponents(string: shareUrl)!
            urlComponents.queryItems = [queryItem, queryItem1, queryItem2, queryItem3]
            let regURL = urlComponents.url
            let webVC = CNWebViewController()
            webVC.url = regURL
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModel3) || (model == kCNDownSlideContentsModelModel4){
            let webVC = CNWebViewController()
//            webVC.url = URL(string: "http://wjjh5.cnlive.com/cnBlockMore.html?channelName=yjzg&pageId=&isShowTitle=true&blockType=28&contentType=13&title=%E5%9B%AD%E9%95%BF%E8%AF%BE%E7%A8%8B&pageName=&moreUrl=https%3A%2F%2Fcmsapi.cnlive.com%2FcontentApi%2FgetBlockContents%3FblockId%3D12165")//"https://managemall.cnlive.com/html/mall/1/#/pages/main/goodsList/goodsList?scene=app")
            webVC.url = URL(string: thirdUrl)
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelAlbum){
            
            let urlString = "http://wjjh5.cnlive.com/cnYmAlbumVideoList.html"
            let queryItem = URLQueryItem(name: "aid", value: contentId)
            let queryItem1 = URLQueryItem(name: "title", value: title)
            let urlComponents = NSURLComponents(string: urlString)
            urlComponents!.queryItems = [queryItem, queryItem1]
            let regURL = urlComponents?.url
            let webVC = CNWebViewController()
            webVC.url = regURL
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelAlbum_video){
            let urlString = "http://wjjh5.cnlive.com/cnYjzgAlbumVideo.html"
            let queryItem = URLQueryItem(name: "aid", value: contentId)
            let queryItem1 = URLQueryItem(name: "title", value: title)
            let queryItem2 = URLQueryItem(name: "channelName", value: "yjzg")
            let queryItem3 = URLQueryItem(name: "isShowTitle", value: "true")
            let queryItem4 = URLQueryItem(name: "isWjjReport", value: "true")
            let urlComponents = NSURLComponents(string: urlString)
            urlComponents!.queryItems = [queryItem, queryItem1,queryItem2,queryItem3,queryItem4]
            let regURL = urlComponents?.url
            let webVC = CNWebViewController()
            webVC.url = regURL
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelAlbum_ugc){
            showLoading(message: "")
            self.pushShortVideoController(contentId: contentId, navigationVC: navigationViewController().visibleViewController?.navigationController, slideModel: slideModel)
        }else if model == kCNDownSlideContentsModelModelServing{
            //跳转微信小程序
            if let data = s_to.data(using: .utf8) {
                do {
                    let jsonResult = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
                    let miniAppId = jsonResult!["id"] as! String
                    let miniPath = jsonResult!["path"] as! String
                    CNLiveShareImageManager.pushWeChatMiniProgrem(withMiniAppId: miniAppId, path: miniPath, extMsg: "", extDic: [:])
                    
                } catch {
                    print("JSON 解析错误")
                }
            } else {
                print("无法将字符串转换为数据")
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelProduct){
            //电商h5--跳转商品页
//            let urlString = "https://managemall.cnlive.com/html/mall/1/#/pages/main/detail/detail?"+"id=\(contentId)&uid=\(UserInfoManager.shared.userInfo.uid)"
            let regURL = URL(string: thirdUrl)
            let webVC = CNWebViewController()
            webVC.url = regURL
            webVC.isHiddenNavigationBar = true
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()

        }else{
            return
        }
    }
    
    class func pushShortVideoController(contentId:String,navigationVC:UINavigationController?,slideModel:CNLiveDownSlideModel?){
        //请求getAlbumMsg获取上次播放集数
        //获取专辑详情(简介等)
        showLoading(message: "")
        CNLiveHomePageViewModel.getAlbumMsg(aid: contentId) { result, status in
            hiddenLoading()
            if status == .success{
                let model = result as! CNLiveAlbumMsgModel
                //短剧-跳转短剧播放页
                let toIndex = model.episodeLast-1 <= 0 ? 0 : model.episodeLast-1
                navigationVC?.pushViewController( CNLiveShortVideoViewController(aid: contentId, currentIndex: toIndex, slideModel: slideModel), animated: pushAnimated)
            }else{
                //短剧-跳转短剧播放页
                navigationVC?.pushViewController(CNLiveShortVideoViewController(aid: contentId), animated: pushAnimated)
            }
        }
    }
    
    class func pushShortVideoController(aid:String,page: NSInteger, currentIndex: NSInteger, dataArray: [CNLiveAlbumListModel],navigationVC:UINavigationController?){
        //请求getAlbumMsg获取上次播放集数
        //获取专辑详情(简介等)
        showLoading(message: "")
        CNLiveHomePageViewModel.getAlbumMsg(aid: aid) { result, status in
            hiddenLoading()
            if status == .success{
                let model = result as! CNLiveAlbumMsgModel
                //短剧-跳转短剧播放页
                let toIndex = model.episodeLast-1 <= 0 ? 0 : model.episodeLast-1
                
                navigationVC?.pushViewController( CNLiveShortVideoViewController(aid: aid, page: page, currentIndex: currentIndex, dataArray: dataArray), animated: pushAnimated)
            }else{
                //短剧-跳转短剧播放页
                navigationVC?.pushViewController(CNLiveShortVideoViewController(aid: aid), animated: pushAnimated)
            }
        }
    }
    
    
    
    // MARK: - 跳转点播或者h5
    class func pushWebAndVodVCWithContentsMdl(model:String,contentId:String,pid:String,shareUrl:String,thirdUrl:String,title:String,s_to:String,trailerId:String,controller:UIViewController?,slideModel:CNLiveDownSlideModel?){//contentMdl:CNLiveDownSlideContentsModel
        showLoading(message: "")
        if (model == kCNDownSlideContentsModelModel1) {//点播-单集
            self.pushVodController(contentId: contentId, navigationVC: navigationViewController().visibleViewController?.navigationController, isAblumVideo: false)

        }else if (model == kCNDownSlideContentsModelModel2){
            let queryItem = URLQueryItem(name: "contentId", value: contentId)
            let queryItem1 = URLQueryItem(name: "activityId", value: pid)
            let queryItem2 = URLQueryItem(name: "pid", value: pid)
            let queryItem3 = URLQueryItem(name: "trailerId", value: trailerId)
            let urlComponents = NSURLComponents(string: shareUrl)!
            urlComponents.queryItems = [queryItem, queryItem1, queryItem2, queryItem3]
            let regURL = urlComponents.url
            let webVC = CNWebViewController()
            webVC.url = regURL
            hiddenLoading()
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
        }else if (model == kCNDownSlideContentsModelModel3) || (model == kCNDownSlideContentsModelModel4){
            let webVC = CNWebViewController()
//            webVC.url = URL(string: "http://wjjh5.cnlive.com/cnBlockMore.html?channelName=yjzg&pageId=&isShowTitle=true&blockType=28&contentType=13&title=%E5%9B%AD%E9%95%BF%E8%AF%BE%E7%A8%8B&pageName=&moreUrl=https%3A%2F%2Fcmsapi.cnlive.com%2FcontentApi%2FgetBlockContents%3FblockId%3D12165")//"https://managemall.cnlive.com/html/mall/1/#/pages/main/goodsList/goodsList?scene=app")
            webVC.url = URL(string: thirdUrl)
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelAlbum_video){
            //点播-专辑
            self.pushVodController(albumId: contentId, navigationVC: navigationViewController().visibleViewController?.navigationController)
//            self.pushVodController(contentId: contentId, navigationVC: navigationViewController().visibleViewController?.navigationController, isAblumVideo: true)
        }else if (model == kCNDownSlideContentsModelModelProduct){
            var urlString = ""
            if thirdUrl.count > 0 ,thirdUrl != "" ,thirdUrl != "null"{
                urlString = thirdUrl
            }else{
                
                urlString = hubilieDSHost+"pages/main/detail/detail?"+"id=\(contentId)&uid=\(UserInfoManager.shared.userInfo.uid)&scene=app"
                //忽必烈专用电商 https://managemall.cnlive.com/html/mall/kublai/#/
//                urlString = "https://managemall.cnlive.com/html/mall/1/#/pages/main/detail/detail?"+"id=\(contentId)&uid=\(UserInfoManager.shared.userInfo.uid)&scene=app"
            }
            let regURL = URL(string: urlString)
            let webVC = CNWebViewController()
            webVC.url = regURL
            webVC.isHiddenNavigationBar = true
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelAlbum){
            let urlString = "http://wjjh5.cnlive.com/cnYjzgAlbumVideo.html"
            let queryItem = URLQueryItem(name: "aid", value: contentId)
            let queryItem1 = URLQueryItem(name: "title", value: title)
            let queryItem2 = URLQueryItem(name: "channelName", value: "yjzg")
            let queryItem3 = URLQueryItem(name: "isShowTitle", value: "true")
            let queryItem4 = URLQueryItem(name: "isWjjReport", value: "true")
            let urlComponents = NSURLComponents(string: urlString)
            urlComponents!.queryItems = [queryItem, queryItem1,queryItem2,queryItem3,queryItem4]
            let regURL = urlComponents?.url
            let webVC = CNWebViewController()
            webVC.url = regURL
            if controller != nil{
                controller!.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }else{
                navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
            }
            hiddenLoading()
        }else if (model == kCNDownSlideContentsModelModelAlbum_ugc){
            showLoading(message: "")
            self.pushShortVideoController(contentId: contentId, navigationVC: navigationViewController().visibleViewController?.navigationController, slideModel: slideModel)
        }else if model == kCNDownSlideContentsModelModelServing{
            hiddenLoading()
            //跳转微信小程序
            if let data = s_to.data(using: .utf8) {
                do {
                    let jsonResult = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
                    let miniAppId = jsonResult!["id"] as! String
                    let miniPath = jsonResult!["path"] as! String
                    CNLiveShareImageManager.pushWeChatMiniProgrem(withMiniAppId: miniAppId, path: miniPath, extMsg: "", extDic: [:])
                    
                } catch {
                    print("JSON 解析错误")
                }
            } else {
                print("无法将字符串转换为数据")
            }
        }else{
            hiddenLoading()
            return
        }
    }
    // MARK: - 跳转电商订单页 type1  state:0全部  1待付款  2待发货  3代收货 ,购物车type2,地址管理type3 ,我的售后type4
    //
    class func pushShopH5WithType(type:String,state:String){
        var urlString = ""
        if type == "1"{
            //订单
            urlString = hubilieDSHost+"pages/orders/orderList/orderList?scene=app&state=\(state)"
        }else if type == "2"{
            //购物车
            urlString = hubilieDSHost+"pages/main/cartList/cartList?scene=app"
        }else if type == "3"{
            //地址管理
            urlString = hubilieDSHost+"pages/users/addressList/addressList?scene=app"
        }else if type == "4"{
            //我的售后
            urlString = hubilieDSHost+"pages/orders/orderList/orderList?state=6"
        }
        let regURL = URL(string: urlString)
        let webVC = CNWebViewController()
        webVC.url = regURL
        webVC.isHiddenNavigationBar = true
        navigationViewController().visibleViewController?.navigationController?.pushViewController(webVC, animated: pushAnimated)
    }
    //刷新使用 获取点播 单集或者专辑数据
    class func getVodData(contentId:String,isAblumVideo:Bool,seleContentId:String,resultBlock: @escaping downSlideVodResultBlock){
        showLoading(message: "")
        if isAblumVideo{
            //专辑
            //获取专辑详情 contentId:2653
            CNLiveDownSlideTool.getVodAlbumMsgApi(contentId: contentId){result, status in
                if status == .success{
                    if let vodModel = result as? CNLiveVodAlbumMsgModel{
                        //获取专辑列表 contentId:2653
                        showLoading(message: "")
                        CNLiveHomePageViewModel.requstWithVodAlbumVideoList(aid: contentId){result, status in
                            hiddenLoading()
                            if let  albumListBaseModel = result as? CNLiveVodAlbumListBaseModel{
                                var currVodModel:CNLiveVodAlbumListModel?
                                for (idx,albumListModel) in  albumListBaseModel.list.enumerated(){
                                    albumListModel.vodAlbumMsgModel = vodModel
                                    let toIndex = vodModel.episodeLast-1 <= 0 ? 0 : vodModel.episodeLast-1
                                    if idx == toIndex{
                                        currVodModel =
                                        albumListModel}
                                }
                                //拿最新播放集数的单集pid,再请求play
                                showLoading(message: "")
                                CNLiveDownSlideTool.getVodPlayApi(contentId:(seleContentId.count>0 ? seleContentId : currVodModel?.contentId ?? "")   ){ result, status in
                                    if status == .success{
                                        if let vodModel = result as? CNLiveVodPlayModel{
                                            //获得点播url
                                            //获取301播放地址
                                            CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: vodModel.contentId) { result, status in
                                    hiddenLoading()
                                    if status == .success{
                                        if let url = result as? String{
                            resultBlock(vodModel,contentId,url,albumListBaseModel, .success)

                                    }

                                        }else{
                                                    
                                        }
                                     }

                                        }else{
                                            
                                        }
                                    }
                                }
                                
                            }
                        }
                    }else{
                        hiddenLoading()
                    }
                }else{
                    hiddenLoading()
                }
            }
            
        }else{
            //单集
            //获取play
            showLoading(message: "")
            CNLiveDownSlideTool.getVodPlayApi(contentId: contentId.count > 0 ? contentId : seleContentId){ result, status in
                if status == .success{
                    if let vodModel = result as? CNLiveVodPlayModel{
                        //获得点播url
                        //获取301播放地址
                        showLoading(message: "")
                        CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: vodModel.contentId) { result, status in
                            hiddenLoading()
                            if status == .success{
                                if let url = result as? String{
                                    resultBlock(vodModel,vodModel.contentId,url,nil,.success)
                                }
                            }else{
                                
                            }
                        }

                    }else{
                        hiddenLoading()
                    }
                }else{
                    hiddenLoading()
                }
            }

        }
    }
    
    //已经确定专辑 ,只有 albumId 2653 ,其他contentId为nil时 跳转点播页
    class func pushVodController(albumId:String,navigationVC:UINavigationController?){
        showLoading(message: "")
//获取专辑详情
CNLiveDownSlideTool.getVodAlbumMsgApi(contentId: albumId){ result, status in
    if status == .success{
        if let vodModel = result as? CNLiveVodAlbumMsgModel{
            //获取专辑列表
            showLoading(message: "")
            CNLiveHomePageViewModel.requstWithVodAlbumVideoList(aid: albumId){result, status in
                if let  albumListBaseModel = result as? CNLiveVodAlbumListBaseModel{
                    var currVodModel:CNLiveVodAlbumListModel?
                    for (idx,albumListModel) in  albumListBaseModel.list.enumerated(){
                        albumListModel.vodAlbumMsgModel = vodModel
                        let toIndex = vodModel.episodeLast-1 <= 0 ? 0 : vodModel.episodeLast-1
                        if idx == toIndex{
                            currVodModel =
                            albumListModel
                        }
                    }
                    if currVodModel == nil{
                        currVodModel = albumListBaseModel.list[0]
                    }
                    //拿最新播放集数的单集pid,再请求play
                    showLoading(message: "")
                    CNLiveDownSlideTool.getVodPlayApi(contentId: currVodModel?.contentId ?? ""){ result, status in
                        if status == .success{
                            if let vodModel = result as? CNLiveVodPlayModel{
                                //获得点播url
                                //获取301播放地址
                                showLoading(message: "")
                                CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: vodModel.contentId) {result,status in //vodModel.contentId result, status in
                                                hiddenLoading()
                                                if status == .success{
                                                    //在当前堆栈里遍历删除 播放控制器CNLiveTVPlayerViewController
                                                    let tempArray = NSMutableArray.init()
                                                    navigationVC?.viewControllers.forEach({ item in
                                                        if (item.isKind(of: CNLiveTVPlayerViewController.self)) {
                                                            tempArray.remove(item)
                                                        }else{
                                                            tempArray.add(item)
                                                        }
                                                    })
                                                    navigationVC?.viewControllers = tempArray as! [UIViewController]
                                                    
                                                    let vc =  CNLiveTVPlayerViewController()
                                                    let url = result as! String
                                                    vc.url = URL(string: url)
                                                    vc.vodPlayModel = vodModel//vodModel
                                                        vc.contentId = vodModel.contentId
                                                    vc.vodAlbumListBaseModel = albumListBaseModel
                                                    let naviVC = CNLiveBaseNavigationController(rootViewController: vc)
                                                    navigationVC?.pushViewController(vc, animated: pushAnimated)
                                                }else{
                                                    
                                                }
                                }
                            }
                        }
                    }
                    
                }
            }
        }
    }
}

    }
    //单集时请求play接口确定是专辑/单集  有contentId 1350755 跳转点播页
    class func pushVodController(contentId:String,navigationVC:UINavigationController?,isAblumVideo:Bool){
showLoading(message: "")
var tempIsAblumVideo = isAblumVideo
//获取play
CNLiveDownSlideTool.getVodPlayApi(contentId: contentId){ result, status in
    if status == .success{
        if let tempVodModel = result as? CNLiveVodPlayModel{
            if tempVodModel.album?.albumId.count ?? 0 > 0{
                //专辑
                //获取专辑详情
                showLoading(message: "")
                CNLiveDownSlideTool.getVodAlbumMsgApi(contentId: tempVodModel.album!.albumId){ result, status in
                    if status == .success{
                        if let vodModel = result as? CNLiveVodAlbumMsgModel{
                            //获取专辑列表
                            showLoading(message: "")
                            CNLiveHomePageViewModel.requstWithVodAlbumVideoList(aid: tempVodModel.album!.albumId){result, status in
                                if let  albumListBaseModel = result as? CNLiveVodAlbumListBaseModel{
                                    var currVodModel:CNLiveVodAlbumListModel?
                                    for (idx,albumListModel) in  albumListBaseModel.list.enumerated(){
                                        albumListModel.vodAlbumMsgModel = vodModel
                                        let toIndex = vodModel.episodeLast-1 <= 0 ? 0 : vodModel.episodeLast-1
                                        if idx == toIndex{
                                            currVodModel =
                                            albumListModel                                    }
                                    }
                                    if currVodModel == nil{
                                        currVodModel = albumListBaseModel.list[0]
                                    }
                                    //拿最新播放集数的单集pid,再请求play
//                                    CNLiveDownSlideTool.getVodPlayApi(contentId: currVodModel?.contentId ?? ""){ result, status in
//                                        if status == .success{
//                                            if let vodModel = result as? CNLiveVodPlayModel{
                                                //获得点播url
                                                //获取301播放地址
                                    showLoading(message: "")
                                    CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: tempVodModel.contentId) {result,status in //vodModel.contentId result, status in
                                                    hiddenLoading()
                                                    if status == .success{
                                                        let vc =  CNLiveTVPlayerViewController()
                                                        let url = result as! String
                                                        vc.url = URL(string: url)
                                                        vc.vodPlayModel = tempVodModel//vodModel
                                                        vc.contentId = contentId
                                                        vc.vodAlbumListBaseModel = albumListBaseModel
                                                        let naviVC = CNLiveBaseNavigationController(rootViewController: vc)
                                                        //在当前堆栈里遍历删除 播放控制器CNLiveTVPlayerViewController
                                                        let tempArray = NSMutableArray.init()
                                                        navigationVC?.viewControllers.forEach({ item in
                                                            if (item.isKind(of: CNLiveTVPlayerViewController.self)) {
                                                                tempArray.remove(item)
                                                            }else{
                                                                tempArray.add(item)
                                                            }
                                                        })
                                                        navigationVC?.viewControllers = tempArray as! [UIViewController]
                                                        navigationVC?.pushViewController(vc, animated: pushAnimated)
                                                    }else{
                                                        
                                                    }
//                                                }
//
//                                            }else{
//                                                
//                                            }
//                                        }
                                    }
                                    
                                }
                            }
                        }
                    }
                }
            }else{
                //单集
                //获得点播url
                //获取301播放地址
                showLoading(message: "")
                CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: tempVodModel.contentId) { result, status in
                    hiddenLoading()
                    if status == .success{
                        //在当前堆栈里遍历删除 播放控制器CNLiveTVPlayerViewController
                        let tempArray = NSMutableArray.init()
                        navigationVC?.viewControllers.forEach({ item in
                            if (item.isKind(of: CNLiveTVPlayerViewController.self)) {
                                tempArray.remove(item)
                            }else{
                                tempArray.add(item)
                            }
                        })
                        navigationVC?.viewControllers = tempArray as! [UIViewController]
                        
                        let vc =  CNLiveTVPlayerViewController()
                        let url = result as! String
                        vc.url = URL(string: url)
                        vc.vodPlayModel = tempVodModel
                        vc.contentId = contentId
                        let naviVC = CNLiveBaseNavigationController(rootViewController: vc)
                        navigationVC?.pushViewController(vc, animated: pushAnimated)
                    }else{
                        
                    }
                }
            }
        }else{
            
        }
    }
    
    func removeTVPlayerViewController(navigationVC:UINavigationController?){
        //在当前堆栈里遍历删除 播放控制器CNLiveTVPlayerViewController
        let tempArray = NSMutableArray.init()
        navigationVC?.viewControllers.forEach({ item in
            if (item.isKind(of: CNLiveTVPlayerViewController.self)) {
                tempArray.remove(item)
            }else{
                tempArray.add(item)
            }
        })
        navigationVC?.viewControllers = tempArray as! [UIViewController]
    }
}
        
        

        
        
        /*
        if isAblumVideo{
            //专辑
            //获取专辑详情
            CNLiveDownSlideTool.getVodAlbumMsgApi(contentId: contentId){result, status in
                if status == .success{
                    if let vodModel = result as? CNLiveVodAlbumMsgModel{
                        //获取专辑列表
                        CNLiveHomePageViewModel.requstWithVodAlbumVideoList(aid: contentId){result, status in
                            if let  albumListBaseModel = result as? CNLiveVodAlbumListBaseModel{
                                var currVodModel:CNLiveVodAlbumListModel?
                                for (idx,albumListModel) in  albumListBaseModel.list.enumerated(){
                                    albumListModel.vodAlbumMsgModel = vodModel
                                    if idx == vodModel.episodeLast{
                                        currVodModel =
                                        albumListModel                                    }
                                }
                                //拿最新播放集数的单集pid,再请求play
                                CNLiveDownSlideTool.getVodPlayApi(contentId: currVodModel?.contentId ?? ""){ result, status in
                                    if status == .success{
                                        if let vodModel = result as? CNLiveVodPlayModel{
                                            //获得点播url
                                            //获取301播放地址
                                            CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: vodModel.contentId) { result, status in
                                                hiddenLoading()
                                                if status == .success{
                                                    let vc =  CNLiveTVPlayerViewController()
                                                    let url = result as! String
                                                    vc.url = URL(string: url)
                                                    vc.vodPlayModel = vodModel
                                                    vc.contentId = contentId
                                                    vc.vodAlbumListBaseModel = albumListBaseModel

                                                    navigationVC?.pushViewController(vc, animated: pushAnimated)
                                                }else{
                                                    
                                                }
                                            }

                                        }else{
                                            
                                        }
                                    }
                                }
                                
                            }
                        }
                    }
                }
            }
            
        }else{
            //单集
            //获取play
            CNLiveDownSlideTool.getVodPlayApi(contentId: contentId){ result, status in
                if status == .success{
                    if let vodModel = result as? CNLiveVodPlayModel{
                        //获得点播url
                        //获取301播放地址
                        CNLiveHomePageViewModel.shared.getVodVideoURL(contentId: vodModel.contentId) { result, status in
                            hiddenLoading()
                            if status == .success{
                                let vc =  CNLiveTVPlayerViewController()
                                let url = result as! String
                                vc.url = URL(string: url)
                                vc.vodPlayModel = vodModel
                                vc.contentId = contentId
                                navigationVC?.pushViewController(vc, animated: pushAnimated)
                            }else{
                                
                            }
                        }

                    }else{
                        
                    }
                }
            }

        }
         */
    }
    
    //专辑详情
    class func getVodAlbumMsgApi(contentId:String,resultBlock: @escaping downSlideResultBlock){
        CNLiveHomePageViewModel.requstWithVodAlbumMsgVideo(aid: contentId) { result, status in
            if status == .success{
                if let albumModel = result as? CNLiveVodAlbumMsgModel{
                    resultBlock(albumModel, .success)
                }
            }else{
                resultBlock(NSNull(), .failed)
            }

        }
    }

    //单集点播 / 专辑获取最新单集的点播
    class func getVodPlayApi(contentId:String,resultBlock: @escaping downSlideResultBlock){
        CNLiveHomePageViewModel.requestGetVodPlayApi(contentId: contentId, sid: UserInfoManager.shared.userInfo.uid, resultBlock: { result, status in
            if status == .success{
                if let vodPlayModel = result as? CNLiveVodPlayModel{
                    resultBlock(vodPlayModel, .success)
                }
            }else{
                resultBlock(NSNull(), .failed)
            }
        })
    }
    //专辑的单集内容
    /*
    class func requestGetVodPlay1Api(contentId:String,resultBlock: @escaping downSlideResultBlock){
        CNLiveHomePageViewModel.requestGetVodPlayApi(contentId: contentId, sid: UserInfoManager.shared.userInfo.uid, resultBlock: { result, status in
            if status == .success{
                if let vodPlayModel = result as? CNLiveVodPlayModel{
                    resultBlock(vodPlayModel, .success)
                }
            }else{
                resultBlock(NSNull(), .failed)
            }
        })
    }
     */




}