|
@@ -0,0 +1,300 @@
|
|
|
+//
|
|
|
+// MVPlayControlViewCell.swift
|
|
|
+// MusicVideoPlus
|
|
|
+//
|
|
|
+// Created by SanW on 2021/6/22.
|
|
|
+//
|
|
|
+
|
|
|
+import BFFramework
|
|
|
+import UIKit
|
|
|
+
|
|
|
+class MVPlayControlViewCell: UICollectionViewCell {
|
|
|
+ let musicWidth: CGFloat = cScreenWidth - 12 - (16 + cDefaultMargin) * 2 - (12 + cDefaultMargin * 7 + 12)
|
|
|
+ var btnClickHandle: ((_ sender: UIButton, _ videoData: PQVideoListModel?) -> Void)?
|
|
|
+ lazy var coverImageView: UIImageView = {
|
|
|
+ let coverImageView = UIImageView()
|
|
|
+ coverImageView.contentMode = .scaleAspectFill
|
|
|
+ coverImageView.isUserInteractionEnabled = true
|
|
|
+ coverImageView.tag = cCellTag
|
|
|
+ coverImageView.backgroundColor = UIColor.white
|
|
|
+ let ges = UITapGestureRecognizer(target: self, action: #selector(tagClick))
|
|
|
+ coverImageView.addGestureRecognizer(ges)
|
|
|
+ return coverImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var pauseBtn: UIButton = {
|
|
|
+ let pauseBtn = UIButton(type: .custom)
|
|
|
+ pauseBtn.setImage(UIImage(named: "video_pause"), for: .selected)
|
|
|
+ pauseBtn.setImage(nil, for: .normal)
|
|
|
+ pauseBtn.tag = 1
|
|
|
+// pauseBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
|
|
|
+ return pauseBtn
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var watchCountLab: UILabel = {
|
|
|
+ let watchCountLab = UILabel()
|
|
|
+ watchCountLab.addShadow()
|
|
|
+ watchCountLab.textColor = UIColor.white
|
|
|
+ watchCountLab.font = UIFont.systemFont(ofSize: 11)
|
|
|
+ return watchCountLab
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var nickNameBtn: UIButton = {
|
|
|
+ let nickNameBtn = UIButton(type: .custom)
|
|
|
+ nickNameBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
|
|
|
+ nickNameBtn.setTitleColor(UIColor.white, for: .normal)
|
|
|
+ nickNameBtn.tag = 2
|
|
|
+ nickNameBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
|
|
|
+ return nickNameBtn
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var musicContenView: UIView = {
|
|
|
+ let musicContenView = UIView()
|
|
|
+ return musicContenView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var musicImageView: UIImageView = {
|
|
|
+ let musicImageView = UIImageView(image: UIImage(named: "musicName_icon"))
|
|
|
+ musicImageView.showLoadingAnimation(duration: 3)
|
|
|
+ return musicImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var musicBgView: UIImageView = {
|
|
|
+ let musicBgView = UIImageView(image: UIImage(named: "musicName_bg"))
|
|
|
+ return musicBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.textAlignment = .left
|
|
|
+ titleLabel.textColor = .white
|
|
|
+ titleLabel.numberOfLines = 5
|
|
|
+ titleLabel.lineBreakMode = .byCharWrapping
|
|
|
+ titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
|
|
|
+ return titleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ /// 音乐歌曲名称
|
|
|
+ lazy var musicNameLab: LMJHorizontalScrollText = {
|
|
|
+ let musicNameLab = LMJHorizontalScrollText(frame: CGRect(x: 12 + cDefaultMargin, y: 0, width: musicWidth, height: 32))
|
|
|
+ musicNameLab.textColor = UIColor.white
|
|
|
+ musicNameLab.textFont = UIFont.systemFont(ofSize: 15, weight: .semibold)
|
|
|
+ musicNameLab.speed = 0.03
|
|
|
+ musicNameLab.moveDirection = LMJTextScrollMoveLeft
|
|
|
+ musicNameLab.moveMode = LMJTextScrollContinuous
|
|
|
+ musicNameLab.stop()
|
|
|
+ return musicNameLab
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var reCreateBtn: UIButton = {
|
|
|
+ let reCreateBtn = UIButton(type: .custom)
|
|
|
+ reCreateBtn.setTitle(" 用此音乐做视频", for: .normal)
|
|
|
+ reCreateBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
|
|
|
+ reCreateBtn.setTitleColor(UIColor.white, for: .normal)
|
|
|
+ reCreateBtn.addCorner(corner: 8)
|
|
|
+ reCreateBtn.setImage(UIImage(named: "reCreate"), for: .normal)
|
|
|
+ reCreateBtn.tag = 3
|
|
|
+ reCreateBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
|
|
|
+ reCreateBtn.backgroundColor = UIColor(red: 61.0 / 255.0, green: 193.0 / 255.0, blue: 193.0 / 255.0, alpha: 0.8)
|
|
|
+ return reCreateBtn
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var wechatImage: UIButton = {
|
|
|
+ let wechatImage = UIButton(type: .custom)
|
|
|
+ wechatImage.setImage(UIImage(named: "mi_upload_share_friend"), for: .normal)
|
|
|
+ wechatImage.tag = 4
|
|
|
+ wechatImage.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
|
|
|
+ wechatImage.layer.shadowColor = UIColor(white: 0, alpha: 0.5).cgColor
|
|
|
+ wechatImage.layer.shadowOffset = CGSize(width: 2, height: 2)
|
|
|
+ return wechatImage
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var wechatLab: UILabel = {
|
|
|
+ let wechatLab = UILabel()
|
|
|
+ wechatLab.textAlignment = .center
|
|
|
+ wechatLab.textColor = UIColor.white
|
|
|
+ wechatLab.font = UIFont.systemFont(ofSize: 13, weight: .medium)
|
|
|
+ wechatLab.text = "分享好友"
|
|
|
+ wechatLab.addShadow()
|
|
|
+ wechatLab.layer.shadowColor = UIColor(white: 0, alpha: 0.5).cgColor
|
|
|
+ wechatLab.layer.shadowOffset = CGSize(width: 2, height: 2)
|
|
|
+ return wechatLab
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var wechatFriImage: UIButton = {
|
|
|
+ let wechatFriImage = UIButton(type: .custom)
|
|
|
+ wechatFriImage.setImage(UIImage(named: "mi_upload_share_timeline"), for: .normal)
|
|
|
+ wechatFriImage.tag = 5
|
|
|
+ wechatFriImage.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
|
|
|
+ wechatFriImage.layer.shadowColor = UIColor(white: 0, alpha: 0.5).cgColor
|
|
|
+ wechatFriImage.layer.shadowOffset = CGSize(width: 2, height: 2)
|
|
|
+ return wechatFriImage
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var wechatFriLab: UILabel = {
|
|
|
+ let wechatFriLab = UILabel()
|
|
|
+ wechatFriLab.textAlignment = .center
|
|
|
+ wechatFriLab.textColor = UIColor.white
|
|
|
+ wechatFriLab.font = UIFont.systemFont(ofSize: 13, weight: .medium)
|
|
|
+ wechatFriLab.text = "分享朋友圈"
|
|
|
+ wechatFriLab.addShadow()
|
|
|
+ wechatFriLab.layer.shadowColor = UIColor(white: 0, alpha: 0.5).cgColor
|
|
|
+ wechatFriLab.layer.shadowOffset = CGSize(width: 2, height: 2)
|
|
|
+ return wechatFriLab
|
|
|
+ }()
|
|
|
+
|
|
|
+ override init(frame: CGRect) {
|
|
|
+ super.init(frame: frame)
|
|
|
+ addSubview(coverImageView)
|
|
|
+ addSubview(pauseBtn)
|
|
|
+ addSubview(watchCountLab)
|
|
|
+ addSubview(nickNameBtn)
|
|
|
+ addSubview(titleLabel)
|
|
|
+ addSubview(musicContenView)
|
|
|
+ musicContenView.addSubview(musicBgView)
|
|
|
+ musicContenView.addSubview(musicImageView)
|
|
|
+ musicBgView.addSubview(musicNameLab)
|
|
|
+ addSubview(reCreateBtn)
|
|
|
+ addSubview(wechatImage)
|
|
|
+ addSubview(wechatLab)
|
|
|
+ addSubview(wechatFriImage)
|
|
|
+ addSubview(wechatFriLab)
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder _: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc class func playControlCell(collectionView: UICollectionView, indexPath: IndexPath) -> MVPlayControlViewCell {
|
|
|
+ let cell: MVPlayControlViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: MVPlayControlViewCell.self), for: indexPath) as! MVPlayControlViewCell
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ override func prepareForReuse() {
|
|
|
+ super.prepareForReuse()
|
|
|
+ pauseBtn.isSelected = false
|
|
|
+ }
|
|
|
+
|
|
|
+ var videoData: PQVideoListModel? {
|
|
|
+ didSet {
|
|
|
+ addData()
|
|
|
+ addLayout()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func addData() {
|
|
|
+ pauseBtn.isSelected = false
|
|
|
+ let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : videoData?.coverImg?["coverImgPath"] as! String
|
|
|
+ netImage(url: coverImg, mainView: coverImageView)
|
|
|
+ if videoData?.shareCountFriend != nil, videoData?.shareCountFriend ?? 0 > 0 {
|
|
|
+ wechatLab.text = (videoData?.shareCountFriend ?? 0).changeUnit()
|
|
|
+ } else {
|
|
|
+ wechatLab.text = "分享好友"
|
|
|
+ }
|
|
|
+ if videoData?.shareCount != nil, videoData?.shareCount ?? 0 > 0 {
|
|
|
+ wechatFriLab.text = (videoData?.shareCount ?? 0).changeUnit()
|
|
|
+ } else {
|
|
|
+ wechatFriLab.text = "分享朋友圈"
|
|
|
+ }
|
|
|
+ watchCountLab.text = "\(videoData?.playCountFormatStr ?? "0")次观看"
|
|
|
+ nickNameBtn.setTitle("@\(videoData?.userInfo?.nickName ?? "")", for: .normal)
|
|
|
+ titleLabel.text = videoData?.title ?? ""
|
|
|
+ let nameWidth: CGFloat = sizeWithText(text: "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") ", font: UIFont.systemFont(ofSize: 15, weight: .semibold), size: CGSize(width: cScreenWidth, height: 32)).width
|
|
|
+ musicNameLab.stop()
|
|
|
+ if nameWidth > musicWidth {
|
|
|
+ musicNameLab.move()
|
|
|
+ musicNameLab.text = "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") "
|
|
|
+ } else {
|
|
|
+ musicNameLab.stop()
|
|
|
+ musicNameLab.text = "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") "
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func addLayout() {
|
|
|
+ let shareW: CGFloat = cDefaultMargin * 7
|
|
|
+ let margin: CGFloat = 12
|
|
|
+ let musicH: CGFloat = 32
|
|
|
+ coverImageView.snp.remakeConstraints { make in
|
|
|
+ make.size.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ pauseBtn.snp.remakeConstraints { make in
|
|
|
+ make.width.height.equalTo(shareW)
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ reCreateBtn.snp.makeConstraints { make in
|
|
|
+ make.left.equalToSuperview().offset(margin)
|
|
|
+ make.right.equalToSuperview().offset(-margin)
|
|
|
+ make.height.equalTo(margin * 4)
|
|
|
+ make.bottom.equalToSuperview().offset(-(cSafeAreaHeight + margin * 4))
|
|
|
+ }
|
|
|
+
|
|
|
+ wechatFriLab.snp.remakeConstraints { make in
|
|
|
+ make.bottom.equalTo(reCreateBtn.snp_top).offset(-cDefaultMargin * 2)
|
|
|
+ make.right.equalTo(reCreateBtn)
|
|
|
+ make.width.equalTo(shareW)
|
|
|
+ }
|
|
|
+
|
|
|
+ wechatFriImage.snp.remakeConstraints { make in
|
|
|
+ make.bottom.equalTo(wechatFriLab.snp_top)
|
|
|
+ make.width.height.equalTo(shareW)
|
|
|
+ make.right.equalTo(wechatFriLab)
|
|
|
+ }
|
|
|
+
|
|
|
+ wechatLab.snp.remakeConstraints { make in
|
|
|
+ make.bottom.equalTo(wechatFriImage.snp_top).offset(-margin)
|
|
|
+ make.width.height.right.equalTo(wechatFriLab)
|
|
|
+ }
|
|
|
+ wechatImage.snp.remakeConstraints { make in
|
|
|
+ make.bottom.equalTo(wechatLab.snp_top)
|
|
|
+ make.width.height.equalTo(shareW)
|
|
|
+ make.right.equalTo(wechatFriLab)
|
|
|
+ }
|
|
|
+
|
|
|
+ musicContenView.snp.remakeConstraints { make in
|
|
|
+ make.height.equalTo(musicH)
|
|
|
+ make.right.equalTo(wechatFriLab.snp_left).offset(-margin)
|
|
|
+ make.left.equalTo(reCreateBtn)
|
|
|
+ make.bottom.equalTo(reCreateBtn.snp_top).offset(-cDefaultMargin * 2)
|
|
|
+ }
|
|
|
+
|
|
|
+ musicImageView.snp.makeConstraints { make in
|
|
|
+ make.top.left.equalToSuperview()
|
|
|
+ make.width.height.equalTo(musicContenView.snp_height)
|
|
|
+ }
|
|
|
+
|
|
|
+ musicBgView.snp.makeConstraints { make in
|
|
|
+ make.left.equalTo(musicImageView.snp_centerX)
|
|
|
+ make.right.top.height.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ titleLabel.snp.remakeConstraints { make in
|
|
|
+ make.bottom.equalTo(musicContenView.snp_top).offset(-margin)
|
|
|
+ make.left.equalTo(reCreateBtn)
|
|
|
+ make.right.equalTo(musicContenView)
|
|
|
+ }
|
|
|
+
|
|
|
+ nickNameBtn.snp.remakeConstraints { make in
|
|
|
+ make.left.equalTo(reCreateBtn)
|
|
|
+ make.bottom.equalTo(titleLabel.snp_top).offset(-margin / 2)
|
|
|
+ }
|
|
|
+
|
|
|
+ watchCountLab.snp.remakeConstraints { make in
|
|
|
+ make.left.equalTo(reCreateBtn)
|
|
|
+ make.right.equalTo(musicContenView)
|
|
|
+ make.bottom.equalTo(nickNameBtn.snp_top).offset(-margin / 2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func tagClick() {
|
|
|
+ pauseBtn.isSelected = !pauseBtn.isSelected
|
|
|
+ btnClick(sender: pauseBtn)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func btnClick(sender: UIButton) {
|
|
|
+ if btnClickHandle != nil {
|
|
|
+ btnClickHandle!(sender, videoData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|