fix: hide media indicator for video

This commit is contained in:
CMK 2021-06-17 18:43:06 +08:00
parent 41322c63e3
commit a1b553a05d
3 changed files with 21 additions and 60 deletions

View File

@ -379,8 +379,7 @@ extension StatusSection {
}() }()
if let videoAttachment = mediaAttachments.filter({ $0.type == .gifv || $0.type == .video }).first, if let videoAttachment = mediaAttachments.filter({ $0.type == .gifv || $0.type == .video }).first,
let videoPlayerViewModel = dependency.context.videoPlaybackService.dequeueVideoPlayerViewModel(for: videoAttachment) let videoPlayerViewModel = dependency.context.videoPlaybackService.dequeueVideoPlayerViewModel(for: videoAttachment) {
{
var parent: UIViewController? var parent: UIViewController?
var playerViewControllerDelegate: AVPlayerViewControllerDelegate? = nil var playerViewControllerDelegate: AVPlayerViewControllerDelegate? = nil
switch cell { switch cell {
@ -408,22 +407,11 @@ extension StatusSection {
playerViewController.player = videoPlayerViewModel.player playerViewController.player = videoPlayerViewModel.player
playerViewController.showsPlaybackControls = videoPlayerViewModel.videoKind != .gif playerViewController.showsPlaybackControls = videoPlayerViewModel.videoKind != .gif
playerContainerView.setMediaKind(kind: videoPlayerViewModel.videoKind) playerContainerView.setMediaKind(kind: videoPlayerViewModel.videoKind)
if videoPlayerViewModel.videoKind == .gif { switch videoPlayerViewModel.videoKind {
case .gif:
playerContainerView.setMediaIndicator(isHidden: false) playerContainerView.setMediaIndicator(isHidden: false)
} else { case .video:
videoPlayerViewModel.timeControlStatus.sink { timeControlStatus in
UIView.animate(withDuration: 0.33) {
switch timeControlStatus {
case .playing:
playerContainerView.setMediaIndicator(isHidden: true) playerContainerView.setMediaIndicator(isHidden: true)
case .paused, .waitingToPlayAtSpecifiedRate:
playerContainerView.setMediaIndicator(isHidden: false)
@unknown default:
assertionFailure()
}
}
}
.store(in: &cell.disposeBag)
} }
playerContainerView.isHidden = false playerContainerView.isHidden = false

View File

@ -9,7 +9,7 @@ import UIKit
extension PlayerContainerView { extension PlayerContainerView {
final class MediaTypeIndicotorView: UIView { final class MediaTypeIndicatorView: UIView {
static let indicatorViewSize = CGSize(width: 47, height: 25) static let indicatorViewSize = CGSize(width: 47, height: 25)
@ -60,7 +60,7 @@ extension PlayerContainerView {
} }
extension PlayerContainerView.MediaTypeIndicotorView { extension PlayerContainerView.MediaTypeIndicatorView {
private func _init() { private func _init() {
backgroundColor = Asset.Colors.Background.mediaTypeIndicotor.color backgroundColor = Asset.Colors.Background.mediaTypeIndicotor.color
@ -87,14 +87,10 @@ extension PlayerContainerView.MediaTypeIndicotorView {
switch kind { switch kind {
case .gif: case .gif:
label.font = PlayerContainerView.MediaTypeIndicotorView.roundedFont(weight: .heavy, fontSize: fontSize) label.font = PlayerContainerView.MediaTypeIndicatorView.roundedFont(weight: .heavy, fontSize: fontSize)
label.text = "GIF" label.text = "GIF"
case .video: case .video:
let configuration = UIImage.SymbolConfiguration(font: PlayerContainerView.MediaTypeIndicotorView.roundedFont(weight: .regular, fontSize: fontSize)) label.text = " "
let image = UIImage(systemName: "video.fill", withConfiguration: configuration)!
let attachment = NSTextAttachment()
attachment.image = image.withTintColor(.white)
label.attributedText = NSAttributedString(attachment: attachment)
} }
} }
@ -103,12 +99,12 @@ extension PlayerContainerView.MediaTypeIndicotorView {
#if canImport(SwiftUI) && DEBUG #if canImport(SwiftUI) && DEBUG
import SwiftUI import SwiftUI
struct PlayerContainerViewMediaTypeIndicotorView_Previews: PreviewProvider { struct PlayerContainerViewMediaTypeIndicatorView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
Group { Group {
UIViewPreview(width: 47) { UIViewPreview(width: 47) {
let view = PlayerContainerView.MediaTypeIndicotorView() let view = PlayerContainerView.MediaTypeIndicatorView()
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
view.heightAnchor.constraint(equalToConstant: 25), view.heightAnchor.constraint(equalToConstant: 25),
@ -118,17 +114,6 @@ struct PlayerContainerViewMediaTypeIndicotorView_Previews: PreviewProvider {
return view return view
} }
.previewLayout(.fixed(width: 47, height: 25)) .previewLayout(.fixed(width: 47, height: 25))
UIViewPreview(width: 47) {
let view = PlayerContainerView.MediaTypeIndicotorView()
view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
view.heightAnchor.constraint(equalToConstant: 25),
view.widthAnchor.constraint(equalToConstant: 47),
])
view.setMediaKind(kind: .video)
return view
}
.previewLayout(.fixed(width: 47, height: 25))
} }
} }

View File

@ -28,8 +28,7 @@ final class PlayerContainerView: UIView {
let playerViewController = AVPlayerViewController() let playerViewController = AVPlayerViewController()
let mediaTypeIndicotorView = MediaTypeIndicotorView() let mediaTypeIndicatorView = MediaTypeIndicatorView()
let mediaTypeIndicotorViewInContentWarningOverlay = MediaTypeIndicotorView()
weak var delegate: PlayerContainerViewDelegate? weak var delegate: PlayerContainerViewDelegate?
@ -66,22 +65,13 @@ extension PlayerContainerView {
playerViewController.view.layer.cornerCurve = .continuous playerViewController.view.layer.cornerCurve = .continuous
// mediaType // mediaType
mediaTypeIndicotorView.translatesAutoresizingMaskIntoConstraints = false mediaTypeIndicatorView.translatesAutoresizingMaskIntoConstraints = false
playerViewController.contentOverlayView!.addSubview(mediaTypeIndicotorView) playerViewController.contentOverlayView!.addSubview(mediaTypeIndicatorView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
mediaTypeIndicotorView.bottomAnchor.constraint(equalTo: playerViewController.contentOverlayView!.bottomAnchor), mediaTypeIndicatorView.bottomAnchor.constraint(equalTo: playerViewController.contentOverlayView!.bottomAnchor),
mediaTypeIndicotorView.rightAnchor.constraint(equalTo: playerViewController.contentOverlayView!.rightAnchor), mediaTypeIndicatorView.rightAnchor.constraint(equalTo: playerViewController.contentOverlayView!.rightAnchor),
mediaTypeIndicotorView.heightAnchor.constraint(equalToConstant: MediaTypeIndicotorView.indicatorViewSize.height).priority(.required - 1), mediaTypeIndicatorView.heightAnchor.constraint(equalToConstant: MediaTypeIndicatorView.indicatorViewSize.height).priority(.required - 1),
mediaTypeIndicotorView.widthAnchor.constraint(equalToConstant: MediaTypeIndicotorView.indicatorViewSize.width).priority(.required - 1), mediaTypeIndicatorView.widthAnchor.constraint(equalToConstant: MediaTypeIndicatorView.indicatorViewSize.width).priority(.required - 1),
])
mediaTypeIndicotorViewInContentWarningOverlay.translatesAutoresizingMaskIntoConstraints = false
contentWarningOverlayView.addSubview(mediaTypeIndicotorViewInContentWarningOverlay)
NSLayoutConstraint.activate([
mediaTypeIndicotorViewInContentWarningOverlay.bottomAnchor.constraint(equalTo: contentWarningOverlayView.bottomAnchor),
mediaTypeIndicotorViewInContentWarningOverlay.rightAnchor.constraint(equalTo: contentWarningOverlayView.rightAnchor),
mediaTypeIndicotorViewInContentWarningOverlay.heightAnchor.constraint(equalToConstant: MediaTypeIndicotorView.indicatorViewSize.height).priority(.required - 1),
mediaTypeIndicotorViewInContentWarningOverlay.widthAnchor.constraint(equalToConstant: MediaTypeIndicotorView.indicatorViewSize.width).priority(.required - 1),
]) ])
contentWarningOverlayView.delegate = self contentWarningOverlayView.delegate = self
@ -149,19 +139,17 @@ extension PlayerContainerView {
contentWarningOverlayView.bottomAnchor.constraint(equalTo: touchBlockingView.bottomAnchor) contentWarningOverlayView.bottomAnchor.constraint(equalTo: touchBlockingView.bottomAnchor)
]) ])
bringSubviewToFront(mediaTypeIndicotorView) bringSubviewToFront(mediaTypeIndicatorView)
return playerViewController return playerViewController
} }
func setMediaKind(kind: VideoPlayerViewModel.Kind) { func setMediaKind(kind: VideoPlayerViewModel.Kind) {
mediaTypeIndicotorView.setMediaKind(kind: kind) mediaTypeIndicatorView.setMediaKind(kind: kind)
mediaTypeIndicotorViewInContentWarningOverlay.setMediaKind(kind: kind)
} }
func setMediaIndicator(isHidden: Bool) { func setMediaIndicator(isHidden: Bool) {
mediaTypeIndicotorView.alpha = isHidden ? 0 : 1 mediaTypeIndicatorView.alpha = isHidden ? 0 : 1
mediaTypeIndicotorViewInContentWarningOverlay.alpha = isHidden ? 0 : 1
} }
} }