Parcourir la source

videoPlayCell

Chris il y a 5 ans
Parent
commit
c9ecdfcc24

+ 37 - 1
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -511,6 +511,9 @@
 		BD20F1D32283D0ED00677D8E /* OrderFinishPaySuccessCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD20F1D22283D0ED00677D8E /* OrderFinishPaySuccessCell.swift */; };
 		BD20F1D52283D15500677D8E /* OrderFinishPayFailureCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD20F1D42283D15500677D8E /* OrderFinishPayFailureCell.swift */; };
 		BD24FABB22B509CF00C7AA3B /* PublishModule.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BD24FABA22B509CF00C7AA3B /* PublishModule.xcassets */; };
+		BD27F0AD22CC5E4D00A6514D /* CommunityVideoListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD27F0AC22CC5E4D00A6514D /* CommunityVideoListController.swift */; };
+		BD27F0B022CC929800A6514D /* CommunityVideoCoverCollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD27F0AF22CC929800A6514D /* CommunityVideoCoverCollectionCell.swift */; };
+		BD27F0B222CC9E2A00A6514D /* CommunityVideoPlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD27F0B122CC9E2A00A6514D /* CommunityVideoPlayView.swift */; };
 		BD29A92E228F99780018CFC3 /* OrderCommentParameterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD29A92D228F99780018CFC3 /* OrderCommentParameterModel.swift */; };
 		BD2FCBE222B21CF70006D974 /* CommunityRecommendController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2FCBE122B21CF70006D974 /* CommunityRecommendController.swift */; };
 		BD2FCBE422B244250006D974 /* RecommendDetailContentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2FCBE322B244250006D974 /* RecommendDetailContentCell.swift */; };
@@ -1212,6 +1215,9 @@
 		BD20F1D22283D0ED00677D8E /* OrderFinishPaySuccessCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderFinishPaySuccessCell.swift; sourceTree = "<group>"; };
 		BD20F1D42283D15500677D8E /* OrderFinishPayFailureCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderFinishPayFailureCell.swift; sourceTree = "<group>"; };
 		BD24FABA22B509CF00C7AA3B /* PublishModule.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = PublishModule.xcassets; sourceTree = "<group>"; };
+		BD27F0AC22CC5E4D00A6514D /* CommunityVideoListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityVideoListController.swift; sourceTree = "<group>"; };
+		BD27F0AF22CC929800A6514D /* CommunityVideoCoverCollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityVideoCoverCollectionCell.swift; sourceTree = "<group>"; };
+		BD27F0B122CC9E2A00A6514D /* CommunityVideoPlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityVideoPlayView.swift; sourceTree = "<group>"; };
 		BD29A92D228F99780018CFC3 /* OrderCommentParameterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCommentParameterModel.swift; sourceTree = "<group>"; };
 		BD2FCBE122B21CF70006D974 /* CommunityRecommendController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityRecommendController.swift; sourceTree = "<group>"; };
 		BD2FCBE322B244250006D974 /* RecommendDetailContentCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendDetailContentCell.swift; sourceTree = "<group>"; };
@@ -1811,6 +1817,7 @@
 				BD2FCBDE22B21BE00006D974 /* CommunityRecommendDetail */,
 				A7C0FDFC22B66B3C00BC1E86 /* CommunityFeaturedTopics */,
 				BD1FC17D22B08CEB00D55081 /* CommunityMyFollowTopic */,
+				BD27F0AA22CC5E0400A6514D /* CommunityVideoContent */,
 			);
 			path = CommunityModule;
 			sourceTree = "<group>";
@@ -4580,8 +4587,8 @@
 		BD1FC17D22B08CEB00D55081 /* CommunityMyFollowTopic */ = {
 			isa = PBXGroup;
 			children = (
-				A7D07CB722B73BAE00186014 /* ViewController */,
 				A7D07CB622B73B9E00186014 /* View */,
+				A7D07CB722B73BAE00186014 /* ViewController */,
 			);
 			path = CommunityMyFollowTopic;
 			sourceTree = "<group>";
@@ -4621,6 +4628,32 @@
 			path = Category;
 			sourceTree = "<group>";
 		};
+		BD27F0AA22CC5E0400A6514D /* CommunityVideoContent */ = {
+			isa = PBXGroup;
+			children = (
+				BD27F0AE22CC8F8F00A6514D /* View */,
+				BD27F0AB22CC5E3400A6514D /* ViewController */,
+			);
+			path = CommunityVideoContent;
+			sourceTree = "<group>";
+		};
+		BD27F0AB22CC5E3400A6514D /* ViewController */ = {
+			isa = PBXGroup;
+			children = (
+				BD27F0AC22CC5E4D00A6514D /* CommunityVideoListController.swift */,
+			);
+			path = ViewController;
+			sourceTree = "<group>";
+		};
+		BD27F0AE22CC8F8F00A6514D /* View */ = {
+			isa = PBXGroup;
+			children = (
+				BD27F0AF22CC929800A6514D /* CommunityVideoCoverCollectionCell.swift */,
+				BD27F0B122CC9E2A00A6514D /* CommunityVideoPlayView.swift */,
+			);
+			path = View;
+			sourceTree = "<group>";
+		};
 		BD2FCBDE22B21BE00006D974 /* CommunityRecommendDetail */ = {
 			isa = PBXGroup;
 			children = (
@@ -5726,6 +5759,7 @@
 				A71AA519227219D7008FF1A5 /* EditExpressAddressViewController.swift in Sources */,
 				A7FF1568228C6E2300A85748 /* OrderDeliveryModeAndTimeTableViewCell.swift in Sources */,
 				A790705B22B9B680008CE279 /* ModifyDataViewController.swift in Sources */,
+				BD27F0B022CC929800A6514D /* CommunityVideoCoverCollectionCell.swift in Sources */,
 				A71738A822897E96000AEA6A /* SwiftMoyaNetWorkServiceShop.swift in Sources */,
 				BD20F1CD2283C51300677D8E /* OrderFinishPayController.swift in Sources */,
 				A729B5B022671310004AE098 /* MobileLoginView.swift in Sources */,
@@ -5769,6 +5803,7 @@
 				A72A72B822321DE000B21995 /* Extension+UserDefaults.swift in Sources */,
 				A719016B22757A5A00104A50 /* ProvinceCityAreaTableViewCell.swift in Sources */,
 				BD12B6AD22B502C200AEB10B /* KSVideoLayer.m in Sources */,
+				BD27F0B222CC9E2A00A6514D /* CommunityVideoPlayView.swift in Sources */,
 				BD6122B122C3638300D3F513 /* AliyunEffectFilterInfo.m in Sources */,
 				A729B5B72267270B004AE098 /* PasswordLoginView.swift in Sources */,
 				BD13B6DF22BA03BC008BB323 /* PublishTopicHeaderView.swift in Sources */,
@@ -6175,6 +6210,7 @@
 				BDD4FB1722840DD3006FE833 /* OrderPayAcountView.swift in Sources */,
 				BDE376DA22C22A260055E2EA /* UIButton+AliyunBlock.m in Sources */,
 				A7D07CBF22B73EE600186014 /* UserPersonalCenterViewController.swift in Sources */,
+				BD27F0AD22CC5E4D00A6514D /* CommunityVideoListController.swift in Sources */,
 				A7CC753C2271C177003C4F38 /* AddressManagerSelfMentionTableViewCell.swift in Sources */,
 				A7FF1587228C851100A85748 /* OrderDetailInfoTableViewCell.swift in Sources */,
 			);

+ 101 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityVideoCoverCollectionCell.swift

@@ -0,0 +1,101 @@
+//
+//  CommunityVideoCoverCollectionCell.swift
+//  RainbowPlanet
+//
+//  Created by Christopher on 2019/7/3.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import RxSwift
+
+class CommunityVideoCoverCollectionCell: UICollectionViewCell {
+    
+    let disposeBag = DisposeBag()
+    
+    var videoItemMdl: CommunityVideoItemModel? {
+        didSet {
+            if !(self.videoItemMdl?.video == nil || self.videoItemMdl?.video == "")  {
+                videoPlayView.assetURLString = self.videoItemMdl?.video
+            }
+        }
+    }
+    
+    
+    typealias DelPicBlock = (_ idxRow:Int?) -> Void
+    var delPicBlock : DelPicBlock?
+    
+    class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> CommunityVideoCoverCollectionCell {
+        let ID = "CommunityVideoCoverCollectionCell"
+        collectionView.register(CommunityVideoCoverCollectionCell.self, forCellWithReuseIdentifier: ID)
+        let cell : CommunityVideoCoverCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! CommunityVideoCoverCollectionCell
+        cell.indexPath = indexPath
+        return cell
+    }
+    //MARK: - indexPath
+    var indexPath: IndexPath?{
+        didSet {
+            
+        }
+    }
+    //MARK: - 初始化
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        backgroundColor = UIColor.white
+        setupViews()
+        setupLayouts()
+        
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    //MRAK: - 设置View
+    private func setupViews() {
+        self.backgroundColor = kf7f8faColor
+        
+        addSubview(videoPlayView)
+        
+        addSubview(delButton)
+    }
+    
+    private func setupLayouts() {
+        
+        videoPlayView.snp.makeConstraints { (make) in
+            make.edges.equalToSuperview()
+        }
+        
+        delButton.snp.makeConstraints { (make) in
+            make.top.right.equalToSuperview()
+            make.size.equalTo(18)
+        }
+    }
+    
+    private lazy var videoPlayView: CommunityVideoPlayView = {
+        let videoPlayView = CommunityVideoPlayView()
+        videoPlayView.isUserInteractionEnabled = true
+        return videoPlayView
+    }()
+    
+    private lazy var picImageView: UIImageView = {
+        let picImageView = UIImageView()
+        picImageView.cornerRadius = 4
+        picImageView.masksToBounds = true
+        return picImageView
+    }()
+    
+    private lazy var delButton: UIButton = {
+        let delButton = UIButton(type: UIButton.ButtonType.custom)
+        delButton.setImage(kImage(name: "common_sku_cancel"), for: UIControl.State.normal)
+        delButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            let idxPath = self?.indexPath
+            if let delPicBlock = self?.delPicBlock {
+                delPicBlock(idxPath?.row)
+            }
+        }).disposed(by: disposeBag)
+        return delButton
+    }()
+    
+}

+ 116 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityVideoPlayView.swift

@@ -0,0 +1,116 @@
+//
+//  CommunityVideoPlayView.swift
+//  RainbowPlanet
+//
+//  Created by Christopher on 2019/7/3.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+
+class CommunityVideoPlayView: UIView {
+    
+    var assetURLString: String? {
+        didSet {
+            
+            if let url = URL(string: assetURLString ?? "") {
+                asset = AVAsset(url: url)
+            }
+            playerItem = AVPlayerItem(asset: asset!)
+            
+            player = AVPlayer(playerItem: playerItem)
+            playerLayer = AVPlayerLayer.init(player: player)
+            playerLayer.videoGravity = .resizeAspectFill
+            self.layer.addSublayer(self.playerLayer)
+            
+        }
+    }
+    private var asset: AVAsset?
+    private var playerItem: AVPlayerItem?
+    private var playerLayer: AVPlayerLayer = AVPlayerLayer.init()
+    private var player: AVPlayer?
+    
+    init() {
+        super.init(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight))
+        initSubView()
+    }
+    
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        initSubView()
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    func initSubView() {
+        playerLayer = AVPlayerLayer.init(player: player)
+        playerLayer.videoGravity = .resizeAspectFill
+        self.layer.addSublayer(self.playerLayer)
+    }
+    
+    override func layoutSubviews() {
+        super.layoutSubviews()
+        CATransaction.begin()
+        CATransaction.setDisableActions(true)
+        playerLayer.frame = self.layer.bounds
+        CATransaction.commit()
+    }
+    
+    
+    
+//    func setupViews() {
+//        self.backgroundColor = kf7f8faColor
+//        addSubview(bgView)
+//        bgView.addSubview(picButton)
+//        bgView.addSubview(titleLabel)
+//    }
+//
+//    func setupLayouts() {
+//        bgView.snp_makeConstraints { (make) in
+//            make.top.equalTo(10)
+//            make.left.right.bottom.equalToSuperview()
+//        }
+//        picButton.snp_makeConstraints { (make) in
+//            make.top.equalTo(20)
+//            make.left.equalTo(15)
+//            make.right.equalTo(-15)
+//            make.height.equalTo(100 * kScaleWidth)
+//        }
+//        titleLabel.snp_makeConstraints { (make) in
+//            make.top.equalTo(picButton.snp_bottom).offset(20)
+//            make.left.equalTo(14)
+//            make.right.equalTo(-14)
+//            make.height.equalTo(25)
+//        }
+//    }
+//
+//    lazy var bgView: UIView = {
+//        let bgView = UIView()
+//        bgView.backgroundColor = .white
+//        return bgView
+//    }()
+//
+//    lazy var picButton: UIButton = {
+//        let picButton = UIButton(type: UIButton.ButtonType.custom)
+//        let configModel = ConfigModel.shared.object()
+//        picButton.kf.setBackgroundImage(with: kURLImage(name: configModel?.findFriendImg ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "pic_preload"))
+//        picButton.cornerRadius = 5
+//        picButton.masksToBounds = true
+//        picButton.rx.tap.subscribe(onNext: { _ in
+//
+//        }).disposed(by: disposeBag)
+//        return picButton
+//    }()
+//
+//    lazy var titleLabel: UILabel = {
+//        let titleLabel = UILabel()
+//        titleLabel.font = kBoldFont18
+//        titleLabel.textColor = k333333Color
+//        titleLabel.text = "推荐关注"
+//        return titleLabel
+//    }()
+    
+    
+}

+ 109 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/ViewController/CommunityVideoListController.swift

@@ -0,0 +1,109 @@
+//
+//  CommunityVideoListController.swift
+//  RainbowPlanet
+//
+//  Created by Christopher on 2019/7/3.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//  推荐--视频内容详情
+
+import UIKit
+import RxSwift
+
+class CommunityVideoListController: BaseViewController {
+    
+    // 内容Id
+    var contentId: Int?
+    
+    var videoItemList: Array<CommunityVideoItemModel>?
+    
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        setupViews()
+        setupData()
+        
+    }
+    
+    override func setupViews() {        
+        
+        self.view.addSubview(collectionView)
+        let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_data"), titleStr: nil, detailStr: "当前暂无数据")
+        emptyView!.contentViewY = kScaleValue(value: 182)
+        collectionView.ly_emptyView = emptyView
+        collectionView.ly_startLoading()
+        collectionView.snp.makeConstraints { (make) in
+            make.top.equalTo(0)
+            make.left.right.bottom.equalToSuperview()
+        }
+        
+    }
+    
+    override func setupData() {
+        collectionView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
+            self?.communityVideoListApi()
+        }
+    }
+    
+    /// 视频列表
+    func communityVideoListApi() {
+        SwiftMoyaNetWorkServiceCommunity.shared().communityVideoListApi(id: contentId ?? 0) {
+            [weak self] (communityVideoListModel) -> (Void) in
+            let videoListMdl = communityVideoListModel as? CommunityVideoListModel
+            self?.videoItemList = videoListMdl?.data
+            self?.collectionView.reloadData()
+        }
+    }
+    
+    private lazy var collectionView: UICollectionView = {
+        let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
+        collectionView.backgroundColor = kf7f8faColor
+        collectionView.delegate = self;
+        collectionView.dataSource = self;
+        collectionView.isPagingEnabled = true
+        collectionView.showsVerticalScrollIndicator = false
+        collectionView.showsHorizontalScrollIndicator = false
+        return collectionView
+    }()
+    
+    private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
+        let collectionViewLayout = UICollectionViewFlowLayout.init()
+        collectionViewLayout.minimumLineSpacing = 0
+        collectionViewLayout.minimumInteritemSpacing = 0
+        return collectionViewLayout
+    }()
+    
+}
+
+// MARK: - collectionView dataSource && delegate
+extension CommunityVideoListController: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
+    func numberOfSections(in collectionView: UICollectionView) -> Int {
+        return 1
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
+        return videoItemList?.count ?? 0
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+        let cell = CommunityVideoCoverCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        cell.videoItemMdl = videoItemList?[indexPath.row]
+        return cell
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        print("----collectionClicked -- \(indexPath.row)")
+    }
+    
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
+        return CGSize(width:kScreenWidth, height:kScreenHeight)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
+        return UIEdgeInsets(top:0, left: 0, bottom: 0, right: 0)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
+        return CGSize(width: kScreenWidth, height: 10)
+    }
+    
+}