123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- //
- // MVHomeController.swift
- // MusicVideoPlus
- //
- // Created by ak on 2021/6/2.
- // 首界面
- import BFFramework
- import BFUIKit
- class MVHomeController: MVBaseController {
- var jumpType: Int = 1 // 跳转类型 type: 1-我的作品 2-再创作 3-卡点视频
- var jumpVideoData: PQVideoListModel?
- var isJumpToLogin: Bool = false
- // 视频播放列表
- public let margin: CGFloat = cDefaultMargin * 3
- public let maxHeight: CGFloat = cScreenHeigth - (cDevice_iPhoneStatusBarHei + 45 + 60 + (cDefaultMargin * 2 + cSafeAreaHeight) + cDefaultMargin * 3)
- lazy var viewListView: MVBanner = {
- let maxWidth: CGFloat = 9.0 / 16.0 * maxHeight
- let margin = (cScreenWidth - maxWidth) / 2
- let lineSpacing = margin - cDefaultMargin * 3
- let videoListView = MVBanner(frame: .zero, margin: margin, lineSpacing: 15, minScale: MVBanner.Scale(scale: 1))
- videoListView.backgroundColor = UIColor.white
- videoListView.register(classCellType: MVBannerCell.self)
- return videoListView
- }()
- // 卡点视频 btn
- lazy var stuckPointBtn: UIButton = {
- let stuckPointBtn = UIButton(type: .custom)
- stuckPointBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- stuckPointBtn.setImage(UIImage(named: "add"), for: .normal)
- stuckPointBtn.adjustsImageWhenHighlighted = false
- stuckPointBtn.tag = 2000
- stuckPointBtn.backgroundColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- stuckPointBtn.addCorner(corner: 30)
- return stuckPointBtn
- }()
- // 个人中心btn
- lazy var mineBtn: UIButton = {
- let mineBtn = UIButton(type: .custom)
- mineBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- mineBtn.setBackgroundImage(UIImage(named: "wode"), for: .normal)
- mineBtn.setImage(UIImage(named: "wode"), for: .normal)
- mineBtn.adjustsImageWhenHighlighted = false
- mineBtn.tag = 1000
- mineBtn.addCorner(corner: cDefaultMargin * 3)
- return mineBtn
- }()
- // 设置btn
- lazy var settingBtn: UIButton = {
- let settingBtn = UIButton(type: .custom)
- settingBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- settingBtn.setBackgroundImage(UIImage(named: "set"), for: .normal)
- settingBtn.adjustsImageWhenHighlighted = false
- settingBtn.tag = 3000
- return settingBtn
- }()
- // 标签分类
- lazy var categoryCollectionView: UICollectionView = {
- let flowLayout = UICollectionViewFlowLayout()
- flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 11, bottom: 0, right: 11)
- flowLayout.minimumLineSpacing = 0
- flowLayout.minimumInteritemSpacing = 0
- flowLayout.scrollDirection = .horizontal
- let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 45), collectionViewLayout: flowLayout)
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.backgroundColor = UIColor.clear
- collectionView.register(MVTagsCell.self, forCellWithReuseIdentifier: String(describing: MVTagsCell.self))
- if #available(iOS 11.0, *) {
- collectionView.contentInsetAdjustmentBehavior = .never
- } else {
- automaticallyAdjustsScrollViewInsets = false
- }
- // 延迟scrollView上子视图的响应,所以当直接拖动UISlider时,如果此时touch时间在150ms以内,UIScrollView会认为是拖动自己,从而拦截了event,导致UISlider接收不到滑动的event
- collectionView.delaysContentTouches = false
- return collectionView
- }()
-
- //网络错误提示
- lazy var emptyRemindView: BFEmptyRemindView = {
- let emptyRemindView = BFEmptyRemindView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
- emptyRemindView.fullRefreshBloc = { [weak self] _, _ in
- self?.getData()
-
- }
- emptyRemindView.isNetLost = true
- emptyRemindView.remindLab.textColor = .black
- emptyRemindView.remindLab.text = "网络错误"
- emptyRemindView.remindLab.font = UIFont.boldSystemFont(ofSize: 20)
- emptyRemindView.imageView.image = nil
- emptyRemindView.remindSubLab.text = "请检查网络后重试"
- emptyRemindView.remindSubLab.isHidden = false
- emptyRemindView.refreshBtn.isHidden = false
- emptyRemindView.refreshBtn.backgroundColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
- emptyRemindView.refreshBtn.setTitle("重试", for: .normal)
-
- return emptyRemindView
- }()
- var mVideos: Array = Array<MVHotVideoModel>.init()
- var mAllVideos: Array = Array<PQVideoListModel>.init()
- var lastBnnerSelectIndex: IndexPath = IndexPath(row: 0, section: 0)
- // 是否点击的再创作
- var isCreateVideo: Bool = false
- deinit {
- PQNotification.removeObserver(self)
- }
- // 登录成功后自动跳转到系统相册
- @objc func loginSuccesss() {
- if isJumpToLogin {
- isJumpToLogin = false
- PQNotification.removeObserver(self)
- // 跳转上传详情页
- jumpToDetailVc(type: jumpType, videoData: jumpVideoData)
- }
- }
- @objc func enterBackground() {
- BFLog(message: "进入到后台")
- var rootViewController = UIApplication.shared.keyWindow?.rootViewController
- if rootViewController is UINavigationController {
- rootViewController = (rootViewController as? UINavigationController)?.visibleViewController
- }
- BFLog(message: "rootViewController is \(String(describing: rootViewController))")
- if rootViewController is MVHomeController {
- controlPlayrPasueOrResume(isPause: true)
- }
- }
- @objc func willEnterForeground() {
- BFLog(message: "进入到前台")
- var rootViewController = UIApplication.shared.keyWindow?.rootViewController
- if rootViewController is UINavigationController {
- rootViewController = (rootViewController as? UINavigationController)?.visibleViewController
- }
- BFLog(message: "rootViewController is \(String(describing: rootViewController))")
- if rootViewController is MVHomeController {
- controlPlayrPasueOrResume(isPause: false)
- }
- }
- override func viewWillAppear(_: Bool) {
- super.viewWillAppear(true)
- controlPlayrPasueOrResume(isPause: false)
- // PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
- // PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
- PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.willResignActiveNotification, object: nil)
- PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.didBecomeActiveNotification, object: nil)
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- controlPlayrPasueOrResume(isPause: true)
- }
-
- override func viewDidDisappear(_ animated: Bool) {
- super.viewDidDisappear(animated)
- controlPlayrPasueOrResume(isPause: true)
- }
- func getData() {
-
- BFLoadingHUB.shared.showHUB(superView:view)
- MVHomeViewModel.getHomeHotVideos { [weak self] hotVideos, msg in
- if(msg == nil){
- BFLog(1, message: "hotVideos count is :\(hotVideos.count)")
- BFLoadingHUB.shared.dismissHUB(superView:(self?.view)!)
- self?.showNetworkError(isHidden: true)
- self?.refreshData(hotVideos: hotVideos)
- }else{
- BFLog(message: "请求数据出错 :\(String(describing: msg))")
- self?.showNetworkError(isHidden: false)
- }
-
-
-
- }
- }
-
- //显示网络未连接提示
- func showNetworkError(isHidden:Bool) {
-
- //有数据时不进行操作
- if(MVHotVideoModel.getCacheData().count != 0){
- return
- }
- if(isHidden){
- emptyRemindView.removeFromSuperview()
- }else{
- view.addSubview(emptyRemindView)
- }
-
- }
-
- func refreshData( hotVideos:Array<MVHotVideoModel>) {
-
- mVideos = hotVideos
- categoryCollectionView.reloadData()
- if mVideos.count > 0 {
- mVideos[0].isSelected = true
- for hotModel in mVideos {
- for video in hotModel.videos {
- mAllVideos.append(video)
- }
- }
- BFLog(message: " self?.mAllVideos count is \(String(describing: mAllVideos.count))")
- }
- viewListView.reloadData()
- // 自动播放第一个视频 确保 reloaddata 完成
- // playVideo(page: 0)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- addNotification(self, selector: #selector(stuckPointDismiss), name: cFinishedPublishedNotiKey, object: nil)
- view.addSubview(mineBtn)
- view.addSubview(stuckPointBtn)
- view.addSubview(settingBtn)
- view.addSubview(viewListView)
- view.addSubview(categoryCollectionView)
- viewListView.dataSource = self
- viewListView.delegate = self
- viewListView.isShowPageControl = false
- viewListView.reloadData()
- addLayout()
- // 请求用户状态
- getUserInfo()
- // 网络监听有网后取一次数据
- manager?.startListening(onUpdatePerforming: { [weak self] status in
- if status == .reachable(.cellular) || status == .reachable(.ethernetOrWiFi) {
- BFLog(message: "来网了")
- self?.showNetworkError(isHidden: true)
- self?.getData()
- } else {
- let cacheData = MVHotVideoModel.getCacheData()
- if(cacheData.count == 0 && self?.mAllVideos.count ?? 0 == 0){
- self?.showNetworkError(isHidden: false)
- }else{
- //没有网时查看有无缓存
- if(cacheData.count > 0){
- BFLog(message: "有缓存数据 ")
- self?.refreshData(hotVideos: cacheData)
- }
- }
-
- }
- })
- // 播放器进度和状态回调
- PQSingletoVideoPlayer.shared.progressBloc = { [weak self] _, playProgress, duration in
- // BFLog(message: "duration \(duration) playProgress\(playProgress) \(duration) 进度\(playProgress / duration)")
- let cell: MVBannerCell? = self?.viewListView.collectionView.cellForItem(at: self?.lastBnnerSelectIndex ?? IndexPath()) as? MVBannerCell
- cell?.progressView.progress = playProgress / duration
- }
- // 添加协议
- let showProtocal: String? = getUserDefaults(key: cShowProtocal) as? String
- if showProtocal == nil || showProtocal?.count ?? 0 <= 0 || showProtocal != "1" {
- let protocalView: PQServerProtocalView = PQServerProtocalView(frame: view.frame)
- protocalView.tag = cProtocalViewTag
- protocalView.remindBlock = { [weak self] sender, webUrl in
- if sender == nil, webUrl != nil {
- let detail = BFBaseWebViewController()
- detail.baseUrl = webUrl
- self?.navigationController?.pushViewController(detail, animated: true)
- }
- // 移除继续播放
- if sender != nil {
- self?.playVideo(page: 0)
- }
- }
- UIApplication.shared.keyWindow?.addSubview(protocalView)
- }
- // try? AVAudioSession.sharedInstance().setCategory(.playback)
- }
- func addLayout() {
- categoryCollectionView.snp.remakeConstraints { make in
- make.width.equalTo(cScreenWidth)
- make.height.equalTo(45)
- make.left.equalToSuperview().offset(0)
- make.top.equalToSuperview().offset(cDevice_iPhoneStatusBarHei)
- }
- stuckPointBtn.snp.remakeConstraints { make in
- make.width.height.equalTo(60)
- make.centerX.equalToSuperview()
- make.bottom.equalToSuperview().offset(-(cDefaultMargin + cAKSafeAreaHeight))
- }
- mineBtn.snp.remakeConstraints { make in
- make.width.height.equalTo(60)
- make.left.equalToSuperview().offset(cDefaultMargin * 3)
- make.centerY.equalTo(stuckPointBtn)
- }
- settingBtn.snp.remakeConstraints { make in
- make.width.height.equalTo(60)
- make.right.equalToSuperview().offset(-cDefaultMargin * 3)
- make.centerY.equalTo(stuckPointBtn)
- }
- viewListView.snp.remakeConstraints { make in
- make.left.right.equalToSuperview()
- make.top.equalTo(categoryCollectionView.snp.bottom).offset(cDefaultMargin)
- make.bottom.equalTo(stuckPointBtn.snp.top).offset(-cDefaultMargin * 2)
- }
- }
- @objc func btnClick(sender: UIButton) {
- switch sender.tag {
- case 1000: // 个人中心
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_clickButton_mineTab, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
-
- jumpToDetailVc(type: 1)
- case 2000: // 系统相册
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_clickButton_syncedUpMusic, pageSource: .sp_shanyinApp_main, extParams: nil, remindmsg: "")
-
- jumpToDetailVc(type: 3)
- case 3000: // 设置
- navigationController?.pushViewController(MVSettingController(), animated: true)
- default:
- break
- }
- }
- /// 判断是否可进入对就界面
- /// - Parameters:
- /// - type: 进入界面 1-我的作品 2-再创作 3-卡点视频
- /// PQVideoListModel 不能为空要使用音乐数据 3,直接创作进入相机
- /// - videoData: type == 2 时必传
- func jumpToDetailVc(type: Int, videoData: PQVideoListModel? = nil) {
- jumpType = type
- jumpVideoData = videoData
- // 无网
- if !isNetConnected() {
-
-
- BFUploadRemindView.showUploadRemindView(title:"似乎已断开与互联网的连接", summary: "", canMoreOpration:true,confirmTitle: "重新连接",cancelTitle:"取消", confirmColor:UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)) { sender, _ in
- if sender.tag == 2 {
- openAppSetting()
- }
- }
-
- return
- }
- // 先判断是否登录
- if !BFLoginUserInfo.shared.isLogin() {
- isJumpToLogin = true
- addNotification(self, selector: #selector(loginSuccesss), name: cLoginSuccesssNotiKey, object: nil)
- let vc = MVLoginController()
- let navigationController: UINavigationController = UINavigationController(rootViewController: vc)
- navigationController.modalPresentationStyle = .fullScreen
- present(navigationController, animated: true, completion: nil)
- return
- }
- // 用户被封禁
- BFLog(message: "userStatus is \(BFLoginUserInfo.shared.userStatus)")
- if BFLoginUserInfo.shared.userStatus == "3" {
- PQBandingPhoneRemindView.accountBlockRemindView(remindTitle: "无法上传视频")
- return
- }
- // 未绑定手机号
- BFLog(message: "phoneNumber is \(BFLoginUserInfo.shared.phoneNumber)")
- if BFLoginUserInfo.shared.phoneNumber.count <= 0 || BFLoginUserInfo.shared.phoneNumber == "<null>" {
- let remindView = PQBandingPhoneRemindView(frame: CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
- remindView.tag = cBandinPhoneTag
- remindView.bandingPhoneRemindHandle = { [weak self] sender in
- if sender.tag == 2 {
- self?.isJumpToLogin = true
- addNotification(self!, selector: #selector(self?.loginSuccesss), name: cBandingPhoneSuccessKey, object: nil)
- self?.navigationController?.pushViewController(PQBandingPhoneController(), animated: true)
- }
- }
- remindView.remindBlock = { [weak self] _, webUrl in
- let detail = BFBaseWebViewController()
- detail.baseUrl = webUrl
- self?.navigationController?.pushViewController(detail, animated: true)
- }
- view.addSubview(remindView)
- return
- }
- // 条件都满足转换到对就界面
- switch type {
- case 1:
- navigationController?.pushViewController(MVMineProductController(), animated: true)
- case 2:
- PQStuckPointViewModel.stuckPointProjectMusicInfo(projectId: videoData?.reCreateVideoData?.projectId ?? "") { [weak self] musicData, _ in
- if musicData != nil {
- let vc = PQStuckPointMaterialController()
- vc.reCreateMusicData = musicData
- vc.reCreateVideoData = videoData?.reCreateVideoData
-
- self?.navigationController?.pushViewController(vc, animated: true)
- // 关闭视频播放
- self?.controlPlayrPasueOrResume(isPause: true)
- } else { BFLog(message: "musicData is ni") }
- }
- case 3:
- let nav = UINavigationController(rootViewController: PQStuckPointMaterialController())
- nav.modalPresentationStyle = .fullScreen
- present(nav, animated: true, completion: nil)
- // 关闭视频播放
- controlPlayrPasueOrResume(isPause: true)
- default:
- break
- }
- }
- // 再创作视频
- func createVideo(indexPath: IndexPath) {
- if mAllVideos.count > indexPath.row {
- isCreateVideo = true
- let videoListModel = mAllVideos[indexPath.row]
-
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_clickButton_syncedUpMusicRecreate, pageSource: .sp_shanyinApp_main, extParams: ["videoId":videoListModel.videoId], remindmsg: "")
-
- jumpToDetailVc(type: 2, videoData: videoListModel)
- } else {
- BFLog(message: "数据出错越界!!! mAllVideos.count: \(mAllVideos.count) indexPath.row: \(indexPath.row)")
- }
- }
- // 卡点模块消失
- @objc func stuckPointDismiss() {
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.01) { [weak self] in
- self?.controlPlayrPasueOrResume(isPause: false)
- }
- }
- /// 获取用户状态信息
- /// - Returns: description
- func getUserInfo() {
- PQMineViewModel.userStatus { _, _ in
- }
- }
- }
- // MARK: - 播放器操作相关方法
- extension MVHomeController {
- /// 播放指定位置的视频
- /// - Parameter page: 视频数据位置
- func playVideo(page: Int) {
- BFLog(1, message: "aa : playVideo")
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.05) {
- if !(UIViewController.getCurrentViewController()?.isMember(of: MVHomeController.self))! {
- BFLog(message: "当前显示的界面不是在首界面,不进行播放")
- return
- }
-
- DispatchQueue.main.async {
- let cell: MVBannerCell? = self.viewListView.collectionView.cellForItem(at: IndexPath(row: page, section: 0)) as? MVBannerCell
- let showProtocal: String? = getUserDefaults(key: cShowProtocal) as? String
- if self.mVideos.count > 0, cell != nil, showProtocal != nil, showProtocal == "1" {
- cell?.pauseView.isHidden = true
- cell?.progressView.progress = 0
- let videoInfo = self.mAllVideos[page]
- videoInfo.playProgress = 0
-
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonView, objectType: .ot_shanyinApp_viewButton_syncedUpMusicRecreate, pageSource: .sp_shanyinApp_main, extParams: ["videoId":videoInfo.videoId], remindmsg: "")
-
- let hotVideoIndex = self.mVideos.firstIndex(where: { (items) -> Bool in
- items.categoryName == videoInfo.categoryName
- })
- BFLog(message: "播放的视频分类为:\(String(describing: self.mVideos[hotVideoIndex ?? 0].categoryName)) hotVideoIndex :\(String(describing: hotVideoIndex)) page is \(page)")
- // 设置选中状态
- for hot in self.mVideos {
- hot.isSelected = false
- }
- self.mVideos[hotVideoIndex ?? 0].isSelected = true
- self.categoryCollectionView.reloadData()
- self.categoryCollectionView.scrollToItem(at: IndexPath(row: hotVideoIndex ?? 0, section: 0), at: .centeredHorizontally, animated: true)
- self.lastBnnerSelectIndex = IndexPath(row: page, section: 0)
-
- PQSingletoVideoPlayer.shared.configPlyer(videoData: videoInfo, controllerView: cell!.converView)
-
-
- self.controlPlayrPasueOrResume(isPause: false)
-
- } else {
- BFLog(message: "播放不成功: cell:\(String(describing: cell)) mVideos:\(self.mVideos.count) showProtocal: is \(String(describing: showProtocal))")
-
- }
- }
- }
- }
- // 控制播放器的暂停或恢复
- func controlPlayrPasueOrResume(isPause: Bool) {
- let cell: MVBannerCell? = viewListView.collectionView.cellForItem(at: lastBnnerSelectIndex) as? MVBannerCell
- BFLog(message: " player isPause is \(isPause)")
- if isPause {
- cell?.pauseView.isHidden = false
- PQSingletoVideoPlayer.shared.pausePlayer()
- } else {
- var rootViewController = UIApplication.shared.keyWindow?.rootViewController
- if rootViewController is UINavigationController {
- rootViewController = (rootViewController as? UINavigationController)?.visibleViewController
- }
- BFLog(message: "rootViewController is \(String(describing: rootViewController))")
- if cell != nil && cell?.videoData != nil{
- cell?.pauseView.isHidden = true
- if cell?.videoData?.videoId == PQSingletoVideoPlayer.shared.playVideoData?.videoId && PQSingletoVideoPlayer.shared.isPlayBegin {
- PQSingletoVideoPlayer.shared.resumePlayer()
- return
- }
- PQSingletoVideoPlayer.shared.configPlyer(videoData: (cell?.videoData)!, controllerView: cell!.converView)
- PQSingletoVideoPlayer.shared.startPlayr()
- PQSingletoVideoPlayer.shared.progressBloc = { [weak self] _, playProgress, duration in
- // BFLog(message: "duration \(duration) playProgress\(playProgress) \(duration) 进度\(playProgress / duration)")
- let cell: MVBannerCell? = self?.viewListView.collectionView.cellForItem(at: self?.lastBnnerSelectIndex ?? IndexPath()) as? MVBannerCell
- cell?.progressView.progress = playProgress / duration
- }
- PQSingletoVideoPlayer.shared.playStatusBloc = { [weak self] status in
- // 播放完成 自动播放下一个
- if status == .PQVIDEO_PLAY_STATUS_END {
- PQSingletoVideoPlayer.shared.playVideoData!.playProgress = 0
- if (self?.lastBnnerSelectIndex.row ?? 0) < (self?.mAllVideos.count ?? 0) - 1 {
- self?.lastBnnerSelectIndex = IndexPath(row: (self?.lastBnnerSelectIndex.row ?? 0) + 1, section: 0)
- // self?.playVideo(page: (self?.lastBnnerSelectIndex ?? IndexPath(row: 0, section: 0)).row)
- // 视频列表跳转
- // self?.viewListView.currentIndex = (self?.lastBnnerSelectIndex ?? IndexPath(row: 0, section: 0)).row
- self?.viewListView.scrollToItem(at: (self?.lastBnnerSelectIndex ?? IndexPath(row: 0, section: 0)).row, animated: false)
- } else {
- BFLog(message: "已经是最后一个视频。")
- cell?.pauseView.isHidden = false
- }
- }
- }
- }
- }
- }
- }
- // MARK: - 视频列表相关代理
- extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
- func numberOfItems() -> Int {
- return mAllVideos.count
- }
- func banner(_ banner: MVBanner, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell: MVBannerCell = banner.dequeueReusableCell(for: indexPath)
- cell.videoData = mAllVideos[indexPath.row]
- cell.reCreateBtnClicHandle = { [weak self] _, _ in
- BFLog(message: "点击了创同款")
- self?.createVideo(indexPath: indexPath)
- }
- cell.sharedBtnClicHandle = {[weak self, weak cell] type in
- if type == 1 {
- // 分享朋友圈
- if !isNetConnected() {
- cShowHUB(superView: self?.view, msg: "没有网络连接")
- return
- }
- if !PQSingletoWXApiUtil.shared.isInstallWX() {
- cShowHUB(superView: self?.view, msg: "您还未安装微信客户端!")
- return
- }
- let shareId = getUniqueId(desc: "\(cell?.videoData?.reCreateVideoData?.videoId ?? "")shareId")
- PQBaseViewModel.h5ShareLinkInfo(videoId: (cell?.videoData?.uniqueId ?? ""), pageSource: cell?.videoData?.pageSource ?? .sp_category) { [weak self] path, _ in
- cHiddenHUB(superView: nil)
- if path != nil {
-
- //判断shareText是否有效
- var shareText = ""
- shareText = cell?.videoData?.title?.replacingOccurrences(of: "\n", with: "") ?? ""
- shareText = shareText.replacingOccurrences(of: " ", with: "")
- if(shareText.count == 0){
- shareText = "\(BFLoginUserInfo.shared.nickName)made a music video for you"
- }
-
- PQSingletoWXApiUtil.shared.share(type: 1, scene: 1, title:shareText , description: "", imageUrl: cell?.videoData?.shareImgPath, path: path, videoId: (cell?.videoData?.uniqueId)!, pageSource: cell?.videoData?.pageSource ?? .sp_category, shareId: shareId).wxApiUtilHander = { _, _ in
-
- }
- } else {
- cShowHUB(superView: self?.view, msg: "没有网络连接")
- }
- }
- // 分享朋友圈上报
- self?.reportUpload(isFriend: false, openId: "", shareId: shareId, videoData: cell?.videoData!)
- }else if type == 2 {
- // 分享微信好友
- if !isNetConnected() {
- cShowHUB(superView: self?.view, msg: "没有网络连接")
- return
- }
- if !PQSingletoWXApiUtil.shared.isInstallWX() {
- cShowHUB(superView: self?.view, msg: "您还未安装微信客户端!")
- return
- }
- cShowHUB(superView: nil, msg: nil)
- let shareId = getUniqueId(desc: "\(cell?.videoData?.uniqueId ?? "")shareId")
- PQBaseViewModel.wxFriendShareInfo(videoId: (cell?.videoData?.uniqueId)!) { [weak self] imagePath, title, shareWeappRawId, msg in
- if msg != nil {
- cShowHUB(superView: self?.view, msg: "网络不佳哦")
- return
- }
- PQSingletoWXApiUtil.shared.share(type: 3, scene: 0, shareWeappRawId: shareWeappRawId, title: title, description: title, imageUrl: imagePath, path: cell?.videoData?.videoPath, videoId: (cell?.videoData?.uniqueId)!, pageSource: cell?.videoData?.pageSource ?? .sp_category, shareId: shareId).wxApiUtilHander = { _, _ in
- }
- cHiddenHUB(superView: nil)
- }
- // 分享好友上报
- self?.reportUpload(isFriend: true, openId: "", shareId: shareId, videoData: cell?.videoData!)
-
- }
- }
- return cell
- }
- func reportUpload(isFriend: Bool, openId _: String, shareId: String, videoData: PQVideoListModel?) {
- // 分享上报
- PQEventTrackViewModel.videoRelationReportUpload(reportLogType: .reportLogType_Action, videoData: videoData, pageSource: nil, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, objectType: nil, extParams: nil, shareId: shareId, videoIds: nil, playId: PQSingletoVideoPlayer.shared.playId)
- if isFriend {
- PQEventTrackViewModel.shareReportUpload(videoId: videoData?.uniqueId ?? "0", pageSource: videoData!.pageSource, recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, flowPool:nil, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, targetUid: videoData?.userInfo?.uid, shareId: shareId)
- PQEventTrackViewModel.shareReportUpload(screenType: 3, videoId: videoData?.uniqueId ?? "0", pageSource: videoData!.pageSource, recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, flowPool:nil, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, targetUid: videoData?.userInfo?.uid, shareId: shareId)
- } else {
- PQEventTrackViewModel.shareReportUpload(screenType: 2, videoId: videoData?.uniqueId ?? "0", pageSource: videoData!.pageSource, recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, flowPool:nil, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: isFriend ? .bt_videoShareFriend : .bt_videoShareH5, targetUid: videoData?.userInfo?.uid, shareId: shareId)
- }
- }
- // MARK: - GXBannerDelegate
- func banner(_: MVBanner, didSelectItemAt indexPath: IndexPath) {
- NSLog("didSelectItemAt %d", indexPath.row)
- lastBnnerSelectIndex = indexPath
- controlPlayrPasueOrResume(isPause: PQSingletoVideoPlayer.shared.isPlaying)
- }
- func pageControl(currentPage page: Int) {
- BFLog(1, message: "page is \(page)")
- playVideo(page: page)
- }
- }
- // MARK: - 划动分类相关代理
- ///
- extension MVHomeController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate {
- func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int {
- return mVideos.count
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let itemData: MVHotVideoModel = mVideos[indexPath.item]
- let cell = MVTagsCell.tagsCell(collectionView: collectionView, indexPath: indexPath)
- cell.bgmData = itemData
- return cell
- }
- func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- let itemData: MVHotVideoModel = mVideos[indexPath.item]
- let width: CGFloat = CGFloat(CGFloat(itemData.categoryName.ga_widthForComment(font: UIFont.boldSystemFont(ofSize: 17), height: 17.0)) + 43)
- return CGSize(width: width, height: collectionView.frame.height - 14)
- }
- func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- for hot in mVideos {
- hot.isSelected = false
- }
- let itemDataNew: MVHotVideoModel = mVideos[indexPath.item]
- itemDataNew.isSelected = true
- categoryCollectionView.reloadData()
- // 找出当前选择分类之前的视频数量和
- var videosCount: Int = 0
- if indexPath.row != 0 {
- for i in 0 ... indexPath.row - 1 {
- videosCount = videosCount + mVideos[i].videos.count
- }
- BFLog(message: "indexPath 选择\(indexPath.item) 之前的视频合\(videosCount)")
- }
- viewListView.currentIndex = videosCount
- viewListView.scrollToItem(at: videosCount, animated: false)
- self.playVideo(page: videosCount)
- }
- }
- extension UIViewController {
- /// 获取当前显示的VC
- ///
- /// - Returns: 当前屏幕显示的VC
- class func getCurrentViewController() -> UIViewController?{
- // 获取当先显示的window
- var currentWindow = UIApplication.shared.keyWindow ?? UIWindow()
- if currentWindow.windowLevel != UIWindow.Level.normal {
- let windowArr = UIApplication.shared.windows
- for window in windowArr {
- if window.windowLevel == UIWindow.Level.normal {
- currentWindow = window
- break
- }
- }
- }
- return UIViewController.getNextXController(nextController: currentWindow.rootViewController)
- }
-
- private class func getNextXController(nextController: UIViewController?) -> UIViewController? {
- if nextController == nil {
- return nil
- }else if nextController?.presentedViewController != nil {
- return UIViewController.getNextXController(nextController: nextController?.presentedViewController)
- }else if let tabbar = nextController as? UITabBarController {
- return UIViewController.getNextXController(nextController: tabbar.selectedViewController)
- }else if let nav = nextController as? UINavigationController {
- return UIViewController.getNextXController(nextController: nav.visibleViewController)
- }
- return nextController
- }
- }
|