Browse Source

1.添加无网重试机制

wenweiwei 3 years ago
parent
commit
ca03d45e47

+ 21 - 0
MusicVideoPlus/Assets.xcassets/Mine/icon_video_refresh.imageset/Contents.json

@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "icon_video_refresh@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

BIN
MusicVideoPlus/Assets.xcassets/Mine/icon_video_refresh.imageset/icon_video_refresh@2x.png


+ 26 - 19
MusicVideoPlus/Classes/Modules/Mine/Controllers/MVPlayViewController.swift

@@ -75,10 +75,12 @@ class MVPlayViewController: PQBaseViewController {
         }
 
         PQSingletoVideoPlayer.shared.playStatusBloc = { [weak self] status in
-            if status == .PQVIDEO_PLAY_STATUS_END {
+            switch status {
+            case .PQVIDEO_PLAY_STATUS_BEGIN:
+                self?.isPlayEnd = false
+            case .PQVIDEO_PLAY_STATUS_END:
                 self?.isPlayEnd = true
                 if ((self?.currentIndex?.item ?? 0) + 1) < (self?.itemsList.count ?? 0) {
-                    //                self?.collectionView.scrollToItem(at: IndexPath(item: (self?.currentIndex?.item ?? 0) + 1, section: 0), at: .top, animated: false)
                     self?.collectionView.contentOffset = CGPoint(x: 0, y: CGFloat((self?.currentIndex?.item ?? 0) + 1) * (self!.collectionView.frame.height))
                     DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2) { [weak self] in
                         self?.scrollViewDidEndDecelerating(self!.collectionView)
@@ -90,8 +92,13 @@ class MVPlayViewController: PQBaseViewController {
                 if (self?.currentIndex?.item ?? 0) >= ((self?.itemsList.count ?? 0) - 2) {
                     self?.loadRequestData(isRefresh: false)
                 }
-            } else if status == .PQVIDEO_PLAY_STATUS_BEGIN {
-                self?.isPlayEnd = false
+            case .PQVIDEO_PLAY_STATUS_RECONNECT:
+                cShowHUB(superView: self?.view, msg: "当前网络不佳,尝试重新连接")
+            case .PQVIDEO_PLAY_STATUS_DISCONNECT:
+                cShowHUB(superView: self?.view, msg: "重新连接失败,请点击重试")
+                (self?.collectionView.visibleCell() as? MVPlayControlViewCell)?.pauseClick(isHidden: false, isSelected: true)
+            default:
+                break
             }
         }
 
@@ -118,9 +125,9 @@ class MVPlayViewController: PQBaseViewController {
     /// - Returns: <#description#>
     func loadRequestData(isRefresh: Bool = true, isAutoPlay _: Bool = false) {
         if !isNetConnected() {
-            cShowHUB(superView: nil, msg: "没有网络连接")
-            collectionView.mj_footer?.endRefreshing(completionBlock: {[weak self] in
-                self?.collectionView.setContentOffset(CGPoint.init(x: 0, y: (self?.collectionView.contentSize.height ?? 0) - (self?.collectionView.frame.height ?? 0)), animated: false)
+            cShowHUB(superView: view, msg: "没有网络连接")
+            collectionView.mj_footer?.endRefreshing(completionBlock: { [weak self] in
+                self?.collectionView.setContentOffset(CGPoint(x: 0, y: (self?.collectionView.contentSize.height ?? 0) - (self?.collectionView.frame.height ?? 0)), animated: false)
             })
             return
         }
@@ -206,7 +213,7 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
         }
         currentIndex = indexPath
         itemData.playProgress = 0
-        cell?.pauseBtn.isSelected = false
+        cell?.pauseClick()
         PQSingletoVideoPlayer.shared.configPlyer(videoData: itemData, controllerView: cell!.coverImageView, renderMode: .RENDER_MODE_FILL_EDGE)
         PQSingletoVideoPlayer.shared.resetPlayer()
         if (indexPath?.item ?? 0) >= itemsList.count - 2 {
@@ -222,10 +229,10 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
     func btnClickHandle(sender: UIButton, videoData: PQVideoListModel?) {
         switch sender.tag {
         case 1: // 暂停/播放
-            if sender.isSelected {
-                PQSingletoVideoPlayer.shared.pausePlayer()
+            if sender.isHidden {
+                PQSingletoVideoPlayer.shared.startPlayr()
             } else {
-                PQSingletoVideoPlayer.shared.resumePlayer()
+                PQSingletoVideoPlayer.shared.pausePlayer()
             }
         case 2: // 昵称
 
@@ -235,18 +242,18 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
             (navVc?.viewControllers.first as? MVHomeController)?.jumpToDetailVc(type: 2, videoData: videoData)
         case 4: // 分享好友
             if !isNetConnected() {
-                cShowHUB(superView: nil, msg: "没有网络连接")
+                cShowHUB(superView: view, msg: "没有网络连接")
                 return
             }
             if !PQSingletoWXApiUtil.shared.isInstallWX() {
-                cShowHUB(superView: nil, msg: "您还未安装微信客户端!")
+                cShowHUB(superView: view, msg: "您还未安装微信客户端!")
                 return
             }
             cShowHUB(superView: nil, msg: nil)
             let shareId = getUniqueId(desc: "\(videoData?.uniqueId ?? "")shareId")
             PQBaseViewModel.wxFriendShareInfo(videoId: (videoData?.uniqueId)!) { [weak self] imagePath, title, shareWeappRawId, msg in
                 if msg != nil {
-                    cShowHUB(superView: nil, msg: "网络不佳哦")
+                    cShowHUB(superView: self?.view, msg: "网络不佳哦")
                     return
                 }
                 PQSingletoWXApiUtil.shared.share(type: 3, scene: Int32(WXSceneSession.rawValue), shareWeappRawId: shareWeappRawId, title: title, description: title, imageUrl: imagePath, path: videoData?.videoPath, videoId: (videoData?.uniqueId)!, pageSource: videoData?.pageSource ?? .sp_category, shareId: shareId).wxApiUtilHander = { _, _ in
@@ -259,11 +266,11 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
             reportUpload(isFriend: true, openId: "", shareId: shareId, videoData: videoData)
         case 5: // 分享朋友圈
             if !isNetConnected() {
-                cShowHUB(superView: nil, msg: "没有网络连接")
+                cShowHUB(superView: view, msg: "没有网络连接")
                 return
             }
             if !PQSingletoWXApiUtil.shared.isInstallWX() {
-                cShowHUB(superView: nil, msg: "您还未安装微信客户端!")
+                cShowHUB(superView: view, msg: "您还未安装微信客户端!")
                 return
             }
             let shareId = getUniqueId(desc: "\(videoData?.uniqueId ?? "")shareId")
@@ -275,7 +282,7 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
                         self?.currentVideoData = videoData
                     }
                 } else {
-                    cShowHUB(superView: nil, msg: "网络不佳哦")
+                    cShowHUB(superView: self?.view, msg: "没有网络连接")
                 }
             }
             // 分享朋友圈上报
@@ -324,7 +331,7 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
         BFLog(message: "进入到后台")
         let navVc: UINavigationController? = (UIApplication.shared.keyWindow?.rootViewController) as? UINavigationController
         if navVc?.visibleViewController is MVPlayViewController {
-            (collectionView.visibleCell() as? MVPlayControlViewCell)?.pauseBtn.isSelected = true
+            (collectionView.visibleCell() as? MVPlayControlViewCell)?.pauseClick(isHidden: false)
             PQSingletoVideoPlayer.shared.stopPlayer(isRemove: false)
         }
     }
@@ -333,7 +340,7 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
         BFLog(message: "进入到前台")
         let navVc: UINavigationController? = (UIApplication.shared.keyWindow?.rootViewController) as? UINavigationController
         if navVc?.visibleViewController is MVPlayViewController {
-            self.scrollViewDidEndDecelerating(collectionView)
+            scrollViewDidEndDecelerating(collectionView)
         }
     }
 

+ 15 - 5
MusicVideoPlus/Classes/Modules/Mine/Views/MVPlayControlViewCell.swift

@@ -32,11 +32,12 @@ class MVPlayControlViewCell: UICollectionViewCell {
 
     lazy var pauseBtn: UIButton = {
         let pauseBtn = UIButton(type: .custom)
-        pauseBtn.setImage(UIImage(named: "video_pause"), for: .selected)
-        pauseBtn.setImage(nil, for: .normal)
+        pauseBtn.setImage(UIImage(named: "video_pause"), for: .normal)
+        pauseBtn.setImage(UIImage(named: "icon_video_refresh"), for: .selected)
         pauseBtn.tag = 1
         pauseBtn.isUserInteractionEnabled = false
 //        pauseBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
+        pauseBtn.isHidden = true
         return pauseBtn
     }()
 
@@ -190,7 +191,7 @@ class MVPlayControlViewCell: UICollectionViewCell {
 
     override func prepareForReuse() {
         super.prepareForReuse()
-        pauseBtn.isSelected = false
+        pauseClick()
         progressView.progress = 0
     }
 
@@ -202,7 +203,7 @@ class MVPlayControlViewCell: UICollectionViewCell {
     }
 
     func addData() {
-        pauseBtn.isSelected = false
+        pauseClick()
         progressView.progress = 0
         let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : videoData?.coverImg?["coverImgPath"] as! String
         coverImageView.setNetImage(url: coverImg)
@@ -321,8 +322,17 @@ class MVPlayControlViewCell: UICollectionViewCell {
         }
     }
 
+    func pauseClick(isHidden:Bool = true,isSelected:Bool = false) -> Void {
+        pauseBtn.isHidden = isHidden
+        pauseBtn.isSelected = isSelected
+    }
+    
     @objc func tagClick() {
-        pauseBtn.isSelected = !pauseBtn.isSelected
+        if pauseBtn.isSelected && !pauseBtn.isHidden && !isNetConnected() {
+            cShowHUB(superView: self, msg: "没有网络连接")
+            return
+        }
+        pauseClick(isHidden: !pauseBtn.isHidden)
         btnClick(sender: pauseBtn)
     }