diff --git a/Source/Assets.xcassets/testpress_logo.imageset/Contents.json b/Source/Assets.xcassets/testpress_logo.imageset/Contents.json new file mode 100644 index 0000000..4c8d8bf --- /dev/null +++ b/Source/Assets.xcassets/testpress_logo.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "testpress_logo.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Source/Assets.xcassets/testpress_logo.imageset/testpress_logo.png b/Source/Assets.xcassets/testpress_logo.imageset/testpress_logo.png new file mode 100644 index 0000000..588eac0 Binary files /dev/null and b/Source/Assets.xcassets/testpress_logo.imageset/testpress_logo.png differ diff --git a/Source/TPStreamPlayerConfiguration.swift b/Source/TPStreamPlayerConfiguration.swift index 93639d2..b6d71ee 100644 --- a/Source/TPStreamPlayerConfiguration.swift +++ b/Source/TPStreamPlayerConfiguration.swift @@ -13,6 +13,16 @@ public struct TPStreamPlayerConfiguration { public var preferredRewindDuration: TimeInterval = 10.0 public var watchedProgressTrackColor: UIColor = .red public var progressBarThumbColor: UIColor = .red + public var brandingImage: UIImage? + public var brandingPosition: BrandingPosition = .topRight + public var brandingMargin: UIEdgeInsets = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 10) +} + +public enum BrandingPosition { + case topLeft + case topRight + case bottomLeft + case bottomRight } @@ -43,6 +53,21 @@ public class TPStreamPlayerConfigurationBuilder { return self } + public func setBrandingImage(_ image: UIImage?) -> Self { + configuration.brandingImage = image + return self + } + + public func setBrandingPosition(_ position: BrandingPosition) -> Self { + configuration.brandingPosition = position + return self + } + + public func setBrandingMargin(_ margin: UIEdgeInsets) -> Self { + configuration.brandingMargin = margin + return self + } + public func build() -> TPStreamPlayerConfiguration { return configuration } diff --git a/Source/TPStreamPlayerViewController.swift b/Source/TPStreamPlayerViewController.swift index fef0f5f..6772842 100644 --- a/Source/TPStreamPlayerViewController.swift +++ b/Source/TPStreamPlayerViewController.swift @@ -15,6 +15,7 @@ public class TPStreamPlayerViewController: UIViewController { public var config = TPStreamPlayerConfiguration(){ didSet { controlsView.playerConfig = config + setupBrandingImage() } } private var controlsVisibilityTimer: Timer? @@ -35,6 +36,8 @@ public class TPStreamPlayerViewController: UIViewController { return view }() + private var brandingImageView = UIImageView() + private lazy var controlsView: PlayerControlsUIView = { guard let view = bundle.loadNibNamed("PlayerControls", owner: nil, options: nil)?.first as? PlayerControlsUIView else { fatalError("Could not load PlayerControls view from nib.") @@ -52,6 +55,7 @@ public class TPStreamPlayerViewController: UIViewController { let view = UIView(frame: view.bounds) view.backgroundColor = .black view.addSubview(videoView) + view.addSubview(brandingImageView) view.addSubview(controlsView) view.bringSubviewToFront(controlsView) return view @@ -96,6 +100,37 @@ public class TPStreamPlayerViewController: UIViewController { } } } + + private func setupBrandingImage(){ + guard let brandingImage = config.brandingImage else { + return + } + + brandingImageView.image = brandingImage +// brandingImageView.frame.origin = getBrandingImageOrigin() + } + + private func getBrandingImageOrigin() -> CGPoint { + let imageWidth = config.brandingImage!.size.width + let imageHeight = config.brandingImage!.size.height + let overallWidth = containerView.bounds.width + let overallHeight = containerView.bounds.height + let marginLeft = config.brandingMargin.left + let marginRight = config.brandingMargin.right + let marginTop = config.brandingMargin.top + let marginBottom = config.brandingMargin.bottom + + switch config.brandingPosition { + case .topLeft: + return CGPoint(x: marginLeft, y: marginTop) + case .topRight: + return CGPoint(x: overallWidth - imageWidth - marginRight, y: marginTop) + case .bottomLeft: + return CGPoint(x: marginLeft, y: overallHeight - imageHeight - marginBottom) + case .bottomRight: + return CGPoint(x: overallWidth - imageWidth - marginRight, y: overallHeight - imageHeight - marginBottom) + } + } } diff --git a/StoryboardExample/ViewController.swift b/StoryboardExample/ViewController.swift index 3fc7097..21682a6 100644 --- a/StoryboardExample/ViewController.swift +++ b/StoryboardExample/ViewController.swift @@ -40,6 +40,7 @@ class ViewController: UIViewController { .setPreferredRewindDuration(5) .setprogressBarThumbColor(.systemBlue) .setwatchedProgressTrackColor(.systemBlue) + .setBrandingImage(UIImage(named: "testpress_logo")) .build() playerViewController?.config = config