|
@@ -16,7 +16,11 @@ class TSAIListVideoPlayerVC: UIViewController {
|
|
|
private var player: AVPlayer?
|
|
|
private var playerLayer: AVPlayerLayer?
|
|
|
private var timeObserverToken: Any?
|
|
|
- private var isPlaying = false
|
|
|
+ private var isPlaying = false{
|
|
|
+ didSet{
|
|
|
+ playPauseButton.setImage(isPlaying ? .videoPause : .videoPlay, for: .normal)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private let videoURL: URL
|
|
|
|
|
@@ -30,17 +34,15 @@ class TSAIListVideoPlayerVC: UIViewController {
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
- private lazy var playPauseButton: UIButton = {
|
|
|
- let button = UIButton()
|
|
|
+ private lazy var playPauseButton: TSUIExpandedTouchButton = {
|
|
|
+ let button = TSUIExpandedTouchButton()
|
|
|
button.setImage(.videoPlay, for: .normal)
|
|
|
button.tintColor = .white
|
|
|
-// button.addTarget(self, action: #selector(playPauseTapped), for: .touchUpInside)
|
|
|
- button.isUserInteractionEnabled = false
|
|
|
+ button.addTarget(self, action: #selector(playPauseTapped), for: .touchUpInside)
|
|
|
return button
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
private lazy var progressSlider: TSProgressSlider = {
|
|
|
let slider = TSProgressSlider()
|
|
|
slider.minimumTrackTintColor = UIColor.themeColor
|
|
@@ -93,17 +95,28 @@ class TSAIListVideoPlayerVC: UIViewController {
|
|
|
removePeriodicTimeObserver()
|
|
|
}
|
|
|
|
|
|
+ @objc private func clickBgView() {
|
|
|
+ setControlsView(isHidden: !controlsContainerView.isHidden)
|
|
|
+ }
|
|
|
+
|
|
|
+ func setControlsView(isHidden:Bool) {
|
|
|
+ playPauseButton.isHidden = isHidden
|
|
|
+ controlsContainerView.isHidden = isHidden
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: - Setup
|
|
|
private func setupUI() {
|
|
|
view.backgroundColor = .clear
|
|
|
- playerContainerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(playPauseTapped)))
|
|
|
+ playerContainerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickBgView)))
|
|
|
view.addSubview(playerContainerView)
|
|
|
- playerContainerView.addSubview(playPauseButton)
|
|
|
+
|
|
|
|
|
|
playerContainerView.snp.makeConstraints { make in
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ playerContainerView.addSubview(playPauseButton)
|
|
|
playPauseButton.snp.makeConstraints { make in
|
|
|
make.centerX.equalToSuperview()
|
|
|
make.centerY.equalToSuperview()//.offset(-50)
|
|
@@ -180,6 +193,11 @@ class TSAIListVideoPlayerVC: UIViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ func runloppPlay() {
|
|
|
+ self.isRunloppPlay = true
|
|
|
+ setControlsView(isHidden: true)
|
|
|
+ playPlay()
|
|
|
+ }
|
|
|
// MARK: - Player Controls
|
|
|
@objc private func playPauseTapped() {
|
|
|
if isPlaying {
|
|
@@ -191,15 +209,11 @@ class TSAIListVideoPlayerVC: UIViewController {
|
|
|
|
|
|
@objc func playPlay() {
|
|
|
player?.play()
|
|
|
- playPauseButton.isHidden = true
|
|
|
- controlsContainerView.isHidden = true
|
|
|
isPlaying = true
|
|
|
}
|
|
|
|
|
|
@objc func playPause() {
|
|
|
player?.pause()
|
|
|
- playPauseButton.isHidden = false
|
|
|
- controlsContainerView.isHidden = false
|
|
|
isPlaying = false
|
|
|
}
|
|
|
|
|
@@ -216,10 +230,7 @@ class TSAIListVideoPlayerVC: UIViewController {
|
|
|
currentTimeLabel.text = "00:00"
|
|
|
|
|
|
if isRunloppPlay {
|
|
|
- player?.play()
|
|
|
- }else{
|
|
|
- playPauseButton.isHidden = false
|
|
|
- controlsContainerView.isHidden = false
|
|
|
+ playPlay()
|
|
|
}
|
|
|
}
|
|
|
// MARK: - Progress Slider
|