瀏覽代碼

1.完成播放详情页

wenweiwei 3 年之前
父節點
當前提交
1284ab69c9

+ 54 - 3
MusicVideoPlus/Classes/Modules/Home/Controllers/MVPlayViewController.swift

@@ -56,6 +56,34 @@ class MVPlayViewController: PQBaseViewController {
         if currentIndex != nil, itemsList.count > (currentIndex?.item ?? 0) {
         if currentIndex != nil, itemsList.count > (currentIndex?.item ?? 0) {
             collectionView.contentOffset = CGPoint(x: 0, y: CGFloat(currentIndex?.item ?? 0) * view.frame.size.height)
             collectionView.contentOffset = CGPoint(x: 0, y: CGFloat(currentIndex?.item ?? 0) * view.frame.size.height)
         }
         }
+
+        PQSingletoVideoPlayer.shared.playStatusBloc = { [weak self] status in
+            if status == .PQVIDEO_PLAY_STATUS_END {
+                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)
+                    }
+                } else {
+                    (self?.collectionView.visibleCell() as? MVPlayControlViewCell)?.tagClick()
+                }
+            }
+        }
+
+        PQSingletoVideoPlayer.shared.progressBloc = { [weak self] _, playProgress, duration in
+            (self?.collectionView.visibleCell() as? MVPlayControlViewCell)?.updateProgress(progress: playProgress / duration)
+        }
+    }
+
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+        PQSingletoVideoPlayer.shared.resumePlayer()
+    }
+
+    override func viewDidDisappear(_ animated: Bool) {
+        super.viewDidDisappear(animated)
+        PQSingletoVideoPlayer.shared.pausePlayer()
     }
     }
 
 
     /// 请求网络数据
     /// 请求网络数据
@@ -75,6 +103,7 @@ class MVPlayViewController: PQBaseViewController {
                     self?.itemsList = self!.itemsList + videoList!
                     self?.itemsList = self!.itemsList + videoList!
                 }
                 }
                 self?.collectionView.reloadData()
                 self?.collectionView.reloadData()
+                self?.scrollViewDidEndDecelerating(self!.collectionView)
             } else {
             } else {
                 self?.pageNum = (self?.pageNum ?? 1) - 1
                 self?.pageNum = (self?.pageNum ?? 1) - 1
             }
             }
@@ -84,7 +113,7 @@ class MVPlayViewController: PQBaseViewController {
     }
     }
 }
 }
 
 
-extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSource {
+extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSource, UIScrollViewDelegate {
     func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int {
     func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int {
         return itemsList.count
         return itemsList.count
     }
     }
@@ -101,6 +130,25 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
 
 
     func collectionView(_: UICollectionView, didSelectItemAt _: IndexPath) {}
     func collectionView(_: UICollectionView, didSelectItemAt _: IndexPath) {}
 
 
+    func scrollViewDidEndDecelerating(_: UIScrollView) {
+        if itemsList.count <= 0 {
+            PQSingletoVideoPlayer.shared.stopPlayer()
+            return
+        }
+        let cell: MVPlayControlViewCell? = collectionView.visibleCell() as? MVPlayControlViewCell
+        if cell == nil {
+            return
+        }
+        let indexPath = collectionView.indexPath(for: cell!)
+        if currentIndex != nil, currentIndex?.item == indexPath?.item {
+            PQSingletoVideoPlayer.shared.resumePlayer()
+            return
+        }
+        currentIndex = indexPath
+        PQSingletoVideoPlayer.shared.configPlyer(videoData: itemsList[indexPath?.item ?? 0], controllerView: cell!.coverImageView)
+        PQSingletoVideoPlayer.shared.startPlayr()
+    }
+
     /// 按钮点击处理
     /// 按钮点击处理
     /// - Parameters:
     /// - Parameters:
     ///   - sender: <#sender description#>
     ///   - sender: <#sender description#>
@@ -109,8 +157,11 @@ extension MVPlayViewController: UICollectionViewDelegate, UICollectionViewDataSo
     func btnClickHandle(sender: UIButton, videoData: PQVideoListModel?) {
     func btnClickHandle(sender: UIButton, videoData: PQVideoListModel?) {
         switch sender.tag {
         switch sender.tag {
         case 1: // 暂停/播放
         case 1: // 暂停/播放
-
-            break
+            if sender.isSelected {
+                PQSingletoVideoPlayer.shared.pausePlayer()
+            } else {
+                PQSingletoVideoPlayer.shared.resumePlayer()
+            }
         case 2: // 昵称
         case 2: // 昵称
 
 
             break
             break

+ 0 - 1
MusicVideoPlus/Classes/Modules/Home/Views/MVBannerCell.swift

@@ -26,7 +26,6 @@ class MVBannerCell: UICollectionViewCell {
         let progressView = UIProgressView(progressViewStyle: .default)
         let progressView = UIProgressView(progressViewStyle: .default)
         progressView.progressTintColor = .white
         progressView.progressTintColor = .white
         return progressView
         return progressView
-
     }()
     }()
 
 
 //    lazy var backShadowView: UIView = {
 //    lazy var backShadowView: UIView = {

+ 29 - 12
MusicVideoPlus/Classes/Modules/Home/Views/MVPlayControlViewCell.swift

@@ -27,6 +27,7 @@ class MVPlayControlViewCell: UICollectionViewCell {
         pauseBtn.setImage(UIImage(named: "video_pause"), for: .selected)
         pauseBtn.setImage(UIImage(named: "video_pause"), for: .selected)
         pauseBtn.setImage(nil, for: .normal)
         pauseBtn.setImage(nil, for: .normal)
         pauseBtn.tag = 1
         pauseBtn.tag = 1
+        pauseBtn.isUserInteractionEnabled = false
 //        pauseBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
 //        pauseBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
         return pauseBtn
         return pauseBtn
     }()
     }()
@@ -143,22 +144,29 @@ class MVPlayControlViewCell: UICollectionViewCell {
         return wechatFriLab
         return wechatFriLab
     }()
     }()
 
 
+    lazy var progressView: UIProgressView = {
+        let progressView = UIProgressView(progressViewStyle: .default)
+        progressView.progressTintColor = .white
+        return progressView
+    }()
+
     override init(frame: CGRect) {
     override init(frame: CGRect) {
         super.init(frame: frame)
         super.init(frame: frame)
-        addSubview(coverImageView)
-        addSubview(pauseBtn)
-        addSubview(watchCountLab)
-        addSubview(nickNameBtn)
-        addSubview(titleLabel)
-        addSubview(musicContenView)
+        contentView.addSubview(coverImageView)
+        contentView.addSubview(pauseBtn)
+        contentView.addSubview(watchCountLab)
+        contentView.addSubview(nickNameBtn)
+        contentView.addSubview(titleLabel)
+        contentView.addSubview(musicContenView)
         musicContenView.addSubview(musicBgView)
         musicContenView.addSubview(musicBgView)
         musicContenView.addSubview(musicImageView)
         musicContenView.addSubview(musicImageView)
         musicBgView.addSubview(musicNameLab)
         musicBgView.addSubview(musicNameLab)
-        addSubview(reCreateBtn)
-        addSubview(wechatImage)
-        addSubview(wechatLab)
-        addSubview(wechatFriImage)
-        addSubview(wechatFriLab)
+        contentView.addSubview(reCreateBtn)
+        contentView.addSubview(wechatImage)
+        contentView.addSubview(wechatLab)
+        contentView.addSubview(wechatFriImage)
+        contentView.addSubview(wechatFriLab)
+        contentView.addSubview(progressView)
     }
     }
 
 
     required init?(coder _: NSCoder) {
     required init?(coder _: NSCoder) {
@@ -210,6 +218,10 @@ class MVPlayControlViewCell: UICollectionViewCell {
         }
         }
     }
     }
 
 
+    func updateProgress(progress: Float) {
+        progressView.setProgress(progress, animated: true)
+    }
+
     func addLayout() {
     func addLayout() {
         let shareW: CGFloat = cDefaultMargin * 7
         let shareW: CGFloat = cDefaultMargin * 7
         let margin: CGFloat = 12
         let margin: CGFloat = 12
@@ -220,7 +232,8 @@ class MVPlayControlViewCell: UICollectionViewCell {
 
 
         pauseBtn.snp.remakeConstraints { make in
         pauseBtn.snp.remakeConstraints { make in
             make.width.height.equalTo(shareW)
             make.width.height.equalTo(shareW)
-            make.center.equalToSuperview()
+            make.centerX.equalToSuperview()
+            make.centerY.equalToSuperview().offset(-cDefaultMargin * 5)
         }
         }
 
 
         reCreateBtn.snp.makeConstraints { make in
         reCreateBtn.snp.makeConstraints { make in
@@ -285,6 +298,10 @@ class MVPlayControlViewCell: UICollectionViewCell {
             make.right.equalTo(musicContenView)
             make.right.equalTo(musicContenView)
             make.bottom.equalTo(nickNameBtn.snp_top).offset(-margin / 2)
             make.bottom.equalTo(nickNameBtn.snp_top).offset(-margin / 2)
         }
         }
+
+        progressView.snp.remakeConstraints { make in
+            make.left.right.bottom.equalToSuperview()
+        }
     }
     }
 
 
     @objc func tagClick() {
     @objc func tagClick() {

+ 1 - 1
MusicVideoPlus/PQConfig.plist

@@ -3,6 +3,6 @@
 <plist version="1.0">
 <plist version="1.0">
 <dict>
 <dict>
 	<key>ENVMode</key>
 	<key>ENVMode</key>
-	<string>ENVModeOnline</string>
+	<string>ENVModeTest</string>
 </dict>
 </dict>
 </plist>
 </plist>