PlayDetailControlView.swift 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // PlayDetailControlView.swift
  3. // ColorfulWallpaper
  4. //
  5. // Created by nkl on 2024/9/13.
  6. //
  7. import Foundation
  8. import Kingfisher
  9. import MarqueeLabel
  10. import SJVideoPlayer
  11. import TSVideoKit
  12. import UIKit
  13. class PlayDetailControlView: UIView {
  14. lazy var titleLabel: MarqueeLabel = {
  15. let title: MarqueeLabel = .init(frame: CGRect(x: 0, y: 0, width: 300, height: 30))
  16. title.trailingBuffer = 20
  17. title.animationDelay = 0
  18. title.speed = .duration(10)
  19. title.font = .boldSystemFont20
  20. title.textAlignment = .center
  21. title.textColor = .white
  22. return title
  23. }()
  24. lazy var detailLabel: UILabel = .simpleLabel(text: "--", font: .systemFont14, color: .white, align: .center)
  25. lazy var topHStack: UIStackView = .hStack
  26. lazy var favouriteButton: UIButton = {
  27. let btn = UIButton()
  28. btn.setImage(UIImage(named: "ic_like"), for: .normal)
  29. btn.setImage(UIImage(named: "ic_like_s"), for: .selected)
  30. return btn
  31. }()
  32. lazy var playlistButton: UIButton = {
  33. let btn = UIButton()
  34. btn.setImage(UIImage(named: "ic_detail_addPlaylist"), for: .normal)
  35. btn.isHidden = true
  36. return btn
  37. }()
  38. lazy var lastButton: UIButton = {
  39. let btn = UIButton()
  40. btn.setLocalizedImage(UIImage(named: "ic_play_last"), for: .normal)
  41. return btn
  42. }()
  43. lazy var playButton: PlayButtonView = PlayButtonView()
  44. lazy var nextButton: UIButton = {
  45. let btn = UIButton()
  46. btn.setLocalizedImage(UIImage(named: "ic_play_next"), for: .normal)
  47. return btn
  48. }()
  49. lazy var progressView: SJProgressSlider = {
  50. let progress = SJProgressSlider()
  51. progress.trackHeight = 4
  52. progress.thumbImageView.image = UIImage(named: "ic_image_thubnail")
  53. progress.trackImageView.backgroundColor = .white.withAlphaComponent(0.1)
  54. progress.traceImageView.backgroundColor = .hexColor("#12FFF7")
  55. progress.traceImageView.contentMode = .scaleAspectFill
  56. progress.isRound = true
  57. progress.animaMaxDuration = 0
  58. progress.tap.isEnabled = true
  59. return progress
  60. }()
  61. lazy var currentLabel: UILabel = .simpleLabel(text: "00:00", font: .systemFont12, color: .hexColor("#B8B9C1"))
  62. lazy var durationLabel: UILabel = .simpleLabel(text: "00:00", font: .systemFont12, color: .hexColor("#B8B9C1"))
  63. lazy var videoHStack: UIStackView = {
  64. let stack: UIStackView = .hStack
  65. stack.distribution = .fillEqually
  66. return stack
  67. }()
  68. lazy var downloadButton: DownloadButton = {
  69. let btn = DownloadButton()
  70. btn.downloadState = .idle(isAnimate: false)
  71. btn.isHidden = true
  72. return btn
  73. }()
  74. lazy var playModelButton: UIButton = {
  75. let btn = UIButton()
  76. btn.setImage(UIImage(named: "ic_cycle"), for: .normal)
  77. return btn
  78. }()
  79. lazy var listButton: UIButton = {
  80. let btn = UIButton()
  81. btn.setImage(UIImage(named: "ic_playdetail_list"), for: .normal)
  82. return btn
  83. }()
  84. lazy var hStackView: UIStackView = {
  85. let stack: UIStackView = .hStack
  86. stack.distribution = .equalSpacing
  87. return stack
  88. }()
  89. lazy var adTag: UIImageView = {
  90. let tag = UIImageView(image: UIImage(named: "detail_ad_tag"))
  91. tag.isHidden = false
  92. return tag
  93. }()
  94. override init(frame: CGRect) {
  95. super.init(frame: frame)
  96. addChildren()
  97. makeConstraints()
  98. }
  99. public func updateTime(currentTime: TimeInterval, duration: TimeInterval) {
  100. let value = currentTime / duration
  101. progressView.value = value
  102. currentLabel.text = currentTime.mmsshh
  103. durationLabel.text = duration.mmsshh
  104. }
  105. public func updateVideoInfo(video: TSVideo) {
  106. titleLabel.text = video.title
  107. detailLabel.text = video.artist
  108. playlistButton.isHidden = video.videoStatus != .cached
  109. downloadButton.isHidden = video.videoStatus == .cached
  110. favouriteButton.isHidden = video.videoStatus != .cached
  111. downloadButton.progressView.set(progress: Double(video.progress))
  112. favouriteButton.isSelected = video.isFavorite
  113. }
  114. public func resetVideoInfo() {
  115. titleLabel.text = "--"
  116. detailLabel.text = "--"
  117. playlistButton.isHidden = true
  118. downloadButton.isHidden = true
  119. }
  120. func resetProgress() {
  121. progressView.value = 0
  122. currentLabel.text = "00:00"
  123. durationLabel.text = "00:00"
  124. }
  125. public func updateProgress(_ progress: Float) {
  126. downloadButton.progressView.set(progress: Double(progress))
  127. }
  128. public func setDefaultDownloadStatus() {
  129. downloadButton.downloadState = .idle(isAnimate: false)
  130. downloadButton.progressView.set(progress: 0)
  131. }
  132. private func addChildren() {
  133. titleLabel.textAlignment = .left
  134. detailLabel.textAlignment = .left
  135. addSubview(titleLabel)
  136. addSubview(detailLabel)
  137. detailLabel.text = ""
  138. addSubview(topHStack)
  139. topHStack.addArrangedSubview(downloadButton)
  140. topHStack.addArrangedSubview(playlistButton)
  141. topHStack.addArrangedSubview(favouriteButton)
  142. addSubview(progressView)
  143. addSubview(currentLabel)
  144. addSubview(durationLabel)
  145. addSubview(videoHStack)
  146. videoHStack.addArrangedSubview(playModelButton)
  147. videoHStack.addArrangedSubview(lastButton)
  148. videoHStack.addArrangedSubview(playButton)
  149. videoHStack.addArrangedSubview(nextButton)
  150. videoHStack.addArrangedSubview(listButton)
  151. }
  152. private func makeConstraints() {
  153. let vRadio = UIScreen.kScreenHeight / 896.0
  154. titleLabel.snp.makeConstraints { make in
  155. make.leading.equalToSuperview().inset(16)
  156. make.trailing.equalTo(topHStack.snp.leading).offset(-12)
  157. make.top.equalToSuperview()
  158. }
  159. detailLabel.snp.makeConstraints { make in
  160. make.leading.equalToSuperview().inset(16)
  161. make.trailing.equalTo(topHStack.snp.leading).offset(-12)
  162. make.top.equalTo(titleLabel.snp.bottom).offset(12 * vRadio)
  163. }
  164. topHStack.snp.makeConstraints { make in
  165. make.trailing.equalToSuperview().offset(-16)
  166. make.centerY.equalTo(titleLabel.snp.bottom)
  167. }
  168. downloadButton.snp.makeConstraints { make in
  169. make.width.height.equalTo(44)
  170. }
  171. playlistButton.snp.makeConstraints { make in
  172. make.width.height.equalTo(44)
  173. }
  174. favouriteButton.snp.makeConstraints { make in
  175. make.width.height.equalTo(44)
  176. }
  177. progressView.snp.makeConstraints { make in
  178. make.leading.equalToSuperview().offset(16)
  179. make.trailing.equalToSuperview().offset(-16)
  180. make.top.equalTo(detailLabel.snp.bottom).offset(44 * vRadio)
  181. make.height.equalTo(50)
  182. }
  183. currentLabel.snp.makeConstraints { make in
  184. if FitManager.isAr {
  185. make.trailing.equalTo(progressView)
  186. } else {
  187. make.leading.equalTo(progressView)
  188. }
  189. make.bottom.equalTo(progressView.snp.top).offset(14)
  190. }
  191. durationLabel.snp.makeConstraints { make in
  192. if FitManager.isAr {
  193. make.leading.equalTo(progressView)
  194. } else {
  195. make.trailing.equalTo(progressView)
  196. }
  197. make.bottom.equalTo(progressView.snp.top).offset(14 * vRadio)
  198. }
  199. videoHStack.snp.makeConstraints { make in
  200. make.top.equalTo(progressView.snp.bottom).offset(20 * vRadio)
  201. make.leading.trailing.equalToSuperview()
  202. make.bottom.equalToSuperview()
  203. }
  204. lastButton.snp.makeConstraints { make in
  205. make.width.height.equalTo(70)
  206. }
  207. playButton.snp.makeConstraints { make in
  208. make.width.height.equalTo(70)
  209. }
  210. nextButton.snp.makeConstraints { make in
  211. make.width.height.equalTo(70)
  212. }
  213. playModelButton.snp.makeConstraints { make in
  214. make.width.height.equalTo(64)
  215. }
  216. listButton.snp.makeConstraints { make in
  217. make.width.height.equalTo(64)
  218. }
  219. }
  220. required init?(coder: NSCoder) {
  221. fatalError("init(coder:) has not been implemented")
  222. }
  223. }