From a18833f602bb78320f14bb6771cb12794a7254d2 Mon Sep 17 00:00:00 2001 From: Lory Date: Tue, 2 Oct 2018 17:42:22 +0200 Subject: [PATCH 1/6] add config option for video layer gravity --- ImageViewer/Source/GalleryConfiguration.swift | 4 ++++ ImageViewer/Source/VideoViewController.swift | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ImageViewer/Source/GalleryConfiguration.swift b/ImageViewer/Source/GalleryConfiguration.swift index e0c914dd..d05312a5 100644 --- a/ImageViewer/Source/GalleryConfiguration.swift +++ b/ImageViewer/Source/GalleryConfiguration.swift @@ -7,6 +7,7 @@ // import UIKit +import AVFoundation public typealias GalleryConfiguration = [GalleryConfigurationItem] @@ -158,6 +159,9 @@ public enum GalleryConfigurationItem { ///Tint color of video controls case videoControlsColor(UIColor) + + /// Change how the video is displayed within a layer’s bounds rectangle + case videoLayerGravity(AVLayerVideoGravity) } public enum GalleryRotationMode { diff --git a/ImageViewer/Source/VideoViewController.swift b/ImageViewer/Source/VideoViewController.swift index f09d7035..ef187eb5 100644 --- a/ImageViewer/Source/VideoViewController.swift +++ b/ImageViewer/Source/VideoViewController.swift @@ -26,6 +26,8 @@ class VideoViewController: ItemBaseController { private var autoPlayStarted: Bool = false private var autoPlayEnabled: Bool = false + + private var videoLayerGravity: AVLayerVideoGravity? = nil init(index: Int, itemCount: Int, fetchImageBlock: @escaping FetchImageBlock, videoURL: URL, scrubber: VideoScrubber, configuration: GalleryConfiguration, isInitialController: Bool = false) { @@ -40,7 +42,8 @@ class VideoViewController: ItemBaseController { case .videoAutoPlay(let enabled): autoPlayEnabled = enabled - + case .videoLayerGravity(let gravity): + videoLayerGravity = gravity default: break } } @@ -61,6 +64,10 @@ class VideoViewController: ItemBaseController { self.itemView.player = player self.itemView.contentMode = .scaleAspectFill + + if let gravity = self.videoLayerGravity { + (self.itemView.layer as? AVPlayerLayer)?.videoGravity = gravity + } } override func viewWillAppear(_ animated: Bool) { From ba24405bcf7cf2a6889db1eb6d17e5c876e7d55e Mon Sep 17 00:00:00 2001 From: Lory Date: Thu, 4 Oct 2018 11:13:38 +0200 Subject: [PATCH 2/6] videoscrubber take safeAreaInset inset to fix UX bad behavior > iOS 11 --- ImageViewer/Source/GalleryViewController.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ImageViewer/Source/GalleryViewController.swift b/ImageViewer/Source/GalleryViewController.swift index 044f8ce5..fa7b1aaf 100644 --- a/ImageViewer/Source/GalleryViewController.swift +++ b/ImageViewer/Source/GalleryViewController.swift @@ -420,7 +420,11 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate { scrubber.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: self.view.bounds.width, height: 40)) scrubber.center = self.view.boundsCenter + scrubber.frame.origin.y = (footerView?.frame.origin.y ?? self.view.bounds.maxY) - scrubber.bounds.height + if #available(iOS 11.0, *) { + scrubber.frame.origin.y = scrubber.frame.origin.y - self.view.safeAreaInsets.bottom + } } @objc fileprivate func deleteItem() { From 7eaf0357cf21c09425f5d2a24cf859932e515598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ge=CC=81doux?= Date: Fri, 24 Apr 2020 19:35:50 +0200 Subject: [PATCH 3/6] clean --- ImageViewer/Source/GalleryConfiguration.swift | 6 +++--- ImageViewer/Source/GalleryViewController.swift | 10 ++++++++++ ImageViewer/Source/VideoViewController.swift | 17 ++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/ImageViewer/Source/GalleryConfiguration.swift b/ImageViewer/Source/GalleryConfiguration.swift index 531ee9c4..10c37f7a 100644 --- a/ImageViewer/Source/GalleryConfiguration.swift +++ b/ImageViewer/Source/GalleryConfiguration.swift @@ -154,9 +154,9 @@ public enum GalleryConfigurationItem { ///Allows the video player to automatically continue playing the next video case continuePlayVideoOnEnd(Bool) - ///Allows auto play video after gallery presented - case videoAutoPlay(Bool) - + ///Allows auto play video at progress after gallery presented + case videoAutoPlay(Bool, Double = 0) + ///Tint color of video controls case videoControlsColor(UIColor) diff --git a/ImageViewer/Source/GalleryViewController.swift b/ImageViewer/Source/GalleryViewController.swift index cef9c182..77850f3e 100644 --- a/ImageViewer/Source/GalleryViewController.swift +++ b/ImageViewer/Source/GalleryViewController.swift @@ -22,6 +22,8 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate { fileprivate var thumbnailsButton: UIButton? = UIButton.thumbnailsButton() fileprivate var deleteButton: UIButton? = UIButton.deleteButton() fileprivate let scrubber = VideoScrubber() + + public var progressCallback: ((Double) -> Void)? fileprivate weak var initialItemController: ItemController? @@ -325,6 +327,14 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate { layoutFooterView() layoutScrubber() } + + open override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + + if let videoViewController = viewControllers?.first as? VideoViewController { + progressCallback?(videoViewController.player.currentTime().seconds) + } + } private var defaultInsets: UIEdgeInsets { if #available(iOS 11.0, *) { diff --git a/ImageViewer/Source/VideoViewController.swift b/ImageViewer/Source/VideoViewController.swift index 0d9c62d6..ca7c35a6 100644 --- a/ImageViewer/Source/VideoViewController.swift +++ b/ImageViewer/Source/VideoViewController.swift @@ -26,7 +26,8 @@ class VideoViewController: ItemBaseController { private var autoPlayStarted: Bool = false private var autoPlayEnabled: Bool = false - + private var autoPlayProgress: Double = 0 + private var videoLayerGravity: AVLayerVideoGravity? = nil init(index: Int, itemCount: Int, fetchImageBlock: @escaping FetchImageBlock, videoURL: URL, scrubber: VideoScrubber, configuration: GalleryConfiguration, isInitialController: Bool = false) { @@ -40,8 +41,9 @@ class VideoViewController: ItemBaseController { switch item { - case .videoAutoPlay(let enabled): + case .videoAutoPlay(let enabled, let progress): autoPlayEnabled = enabled + autoPlayProgress = progress case .videoLayerGravity(let gravity): videoLayerGravity = gravity default: break @@ -111,16 +113,11 @@ class VideoViewController: ItemBaseController { } @objc func playVideoInitially() { - self.player.play() - UIView.animate(withDuration: 0.25, animations: { [weak self] in - self?.embeddedPlayButton.alpha = 0 - }, completion: { [weak self] _ in - self?.embeddedPlayButton.isHidden = true }) } @@ -144,7 +141,6 @@ class VideoViewController: ItemBaseController { } super.presentItem(alongsideAnimation: alongsideAnimation) { - circleButtonAnimation() completion() } @@ -157,14 +153,11 @@ class VideoViewController: ItemBaseController { } override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { - if keyPath == "rate" || keyPath == "status" { - fadeOutEmbeddedPlayButton() } else if keyPath == "contentOffset" { - handleSwipeToDismissTransition() } @@ -236,6 +229,8 @@ class VideoViewController: ItemBaseController { autoPlayStarted = true embeddedPlayButton.isHidden = true + scrubber.player?.seek(to: CMTime(seconds: autoPlayProgress, preferredTimescale: 1)) + scrubber.scrubber.value = Float(autoPlayProgress) * scrubber.scrubber.maximumValue scrubber.play() } } From a4d3127b704994f4d152b344725045fb7b36c796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ge=CC=81doux?= Date: Mon, 27 Apr 2020 13:18:18 +0200 Subject: [PATCH 4/6] update for video in Wizz --- ImageViewer/Source/GalleryConfiguration.swift | 2 +- ImageViewer/Source/GalleryItem.swift | 2 +- .../Source/GalleryPagingDataSource.swift | 4 +- .../ThumbnailsViewController.swift | 2 +- ImageViewer/Source/VideoView.swift | 59 +------------------ ImageViewer/Source/VideoViewController.swift | 15 ++--- 6 files changed, 11 insertions(+), 73 deletions(-) diff --git a/ImageViewer/Source/GalleryConfiguration.swift b/ImageViewer/Source/GalleryConfiguration.swift index 10c37f7a..a5f55a62 100644 --- a/ImageViewer/Source/GalleryConfiguration.swift +++ b/ImageViewer/Source/GalleryConfiguration.swift @@ -155,7 +155,7 @@ public enum GalleryConfigurationItem { case continuePlayVideoOnEnd(Bool) ///Allows auto play video at progress after gallery presented - case videoAutoPlay(Bool, Double = 0) + case videoAutoPlay(Bool) ///Tint color of video controls case videoControlsColor(UIColor) diff --git a/ImageViewer/Source/GalleryItem.swift b/ImageViewer/Source/GalleryItem.swift index 0a8cb0d2..2dfdbeae 100644 --- a/ImageViewer/Source/GalleryItem.swift +++ b/ImageViewer/Source/GalleryItem.swift @@ -15,6 +15,6 @@ public typealias ItemViewControllerBlock = (_ index: Int, _ itemCount: Int, _ fe public enum GalleryItem { case image(fetchImageBlock: FetchImageBlock) - case video(fetchPreviewImageBlock: FetchImageBlock, videoURL: URL) + case video(fetchPreviewImageBlock: FetchImageBlock, videoURL: URL, videoProgress: Double) case custom(fetchImageBlock: FetchImageBlock, itemViewControllerBlock: ItemViewControllerBlock) } diff --git a/ImageViewer/Source/GalleryPagingDataSource.swift b/ImageViewer/Source/GalleryPagingDataSource.swift index 43ccbb22..63db9334 100644 --- a/ImageViewer/Source/GalleryPagingDataSource.swift +++ b/ImageViewer/Source/GalleryPagingDataSource.swift @@ -85,9 +85,9 @@ final class GalleryPagingDataSource: NSObject, UIPageViewControllerDataSource { return imageController - case .video(let fetchImageBlock, let videoURL): + case .video(let fetchImageBlock, let videoURL, let videoProgress): - let videoController = VideoViewController(index: itemIndex, itemCount: itemsDataSource.itemCount(), fetchImageBlock: fetchImageBlock, videoURL: videoURL, scrubber: scrubber, configuration: configuration, isInitialController: isInitial) + let videoController = VideoViewController(index: itemIndex, itemCount: itemsDataSource.itemCount(), fetchImageBlock: fetchImageBlock, videoURL: videoURL, videoProgress: videoProgress, scrubber: scrubber, configuration: configuration, isInitialController: isInitial) videoController.delegate = itemControllerDelegate videoController.displacedViewsDataSource = displacedViewsDataSource diff --git a/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift b/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift index 5555528f..1d6e1bd6 100644 --- a/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift +++ b/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift @@ -116,7 +116,7 @@ class ThumbnailsViewController: UICollectionViewController, UICollectionViewDele } } - case .video(let fetchImageBlock, _): + case .video(let fetchImageBlock, _, _): fetchImageBlock() { image in diff --git a/ImageViewer/Source/VideoView.swift b/ImageViewer/Source/VideoView.swift index 161121b0..1b3b42a4 100644 --- a/ImageViewer/Source/VideoView.swift +++ b/ImageViewer/Source/VideoView.swift @@ -11,29 +11,13 @@ import AVFoundation class VideoView: UIView { - let previewImageView = UIImageView() - var image: UIImage? { didSet { previewImageView.image = image } } + var image: UIImage? var player: AVPlayer? { - - willSet { - - if newValue == nil { - - player?.removeObserver(self, forKeyPath: "status") - player?.removeObserver(self, forKeyPath: "rate") - } - } - didSet { - if let player = self.player, let videoLayer = self.layer as? AVPlayerLayer { - videoLayer.player = player videoLayer.videoGravity = AVLayerVideoGravity.resizeAspect - - player.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.new, context: nil) - player.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.new, context: nil) } } } @@ -41,45 +25,4 @@ class VideoView: UIView { override class var layerClass : AnyClass { return AVPlayerLayer.self } - - convenience init() { - self.init(frame: CGRect.zero) - } - - override init(frame: CGRect) { - super.init(frame: frame) - - self.addSubview(previewImageView) - - previewImageView.contentMode = .scaleAspectFill - previewImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - previewImageView.clipsToBounds = true - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - deinit { - - player?.removeObserver(self, forKeyPath: "status") - player?.removeObserver(self, forKeyPath: "rate") - } - - override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { - - if let status = self.player?.status, let rate = self.player?.rate { - - if status == .readyToPlay && rate != 0 { - - UIView.animate(withDuration: 0.3, animations: { [weak self] in - - if let strongSelf = self { - - strongSelf.previewImageView.alpha = 0 - } - }) - } - } - } } diff --git a/ImageViewer/Source/VideoViewController.swift b/ImageViewer/Source/VideoViewController.swift index ca7c35a6..7ae65ce7 100644 --- a/ImageViewer/Source/VideoViewController.swift +++ b/ImageViewer/Source/VideoViewController.swift @@ -17,6 +17,7 @@ class VideoViewController: ItemBaseController { fileprivate let swipeToDismissFadeOutAccelerationFactor: CGFloat = 6 let videoURL: URL + let videoProgress: Double let player: AVPlayer unowned let scrubber: VideoScrubber @@ -26,24 +27,21 @@ class VideoViewController: ItemBaseController { private var autoPlayStarted: Bool = false private var autoPlayEnabled: Bool = false - private var autoPlayProgress: Double = 0 private var videoLayerGravity: AVLayerVideoGravity? = nil - init(index: Int, itemCount: Int, fetchImageBlock: @escaping FetchImageBlock, videoURL: URL, scrubber: VideoScrubber, configuration: GalleryConfiguration, isInitialController: Bool = false) { + init(index: Int, itemCount: Int, fetchImageBlock: @escaping FetchImageBlock, videoURL: URL, videoProgress: Double, scrubber: VideoScrubber, configuration: GalleryConfiguration, isInitialController: Bool = false) { self.videoURL = videoURL + self.videoProgress = videoProgress self.scrubber = scrubber self.player = AVPlayer(url: self.videoURL) ///Only those options relevant to the paging VideoViewController are explicitly handled here, the rest is handled by ItemViewControllers for item in configuration { - switch item { - - case .videoAutoPlay(let enabled, let progress): + case .videoAutoPlay(let enabled): autoPlayEnabled = enabled - autoPlayProgress = progress case .videoLayerGravity(let gravity): videoLayerGravity = gravity default: break @@ -127,7 +125,6 @@ class VideoViewController: ItemBaseController { UIView.animate(withDuration: duration, animations: { [weak self] in self?.embeddedPlayButton.alpha = 0 - self?.itemView.previewImageView.alpha = 1 }) } @@ -172,7 +169,6 @@ class VideoViewController: ItemBaseController { } func fadeOutEmbeddedPlayButton() { - if player.isPlaying() && embeddedPlayButton.alpha != 0 { UIView.animate(withDuration: 0.3, animations: { [weak self] in @@ -229,8 +225,7 @@ class VideoViewController: ItemBaseController { autoPlayStarted = true embeddedPlayButton.isHidden = true - scrubber.player?.seek(to: CMTime(seconds: autoPlayProgress, preferredTimescale: 1)) - scrubber.scrubber.value = Float(autoPlayProgress) * scrubber.scrubber.maximumValue + scrubber.player?.seek(to: CMTime(seconds: videoProgress, preferredTimescale: 1)) scrubber.play() } } From 055f693f2330216f3c2e02916ac221120305e179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ge=CC=81doux?= Date: Thu, 30 Apr 2020 13:47:32 +0200 Subject: [PATCH 5/6] clean --- ImageViewer/Source/GalleryItem.swift | 4 +-- .../Source/GalleryPagingDataSource.swift | 4 +-- .../Source/GalleryViewController.swift | 2 ++ .../ThumbnailsViewController.swift | 2 +- ImageViewer/Source/VideoScrubber.swift | 1 - ImageViewer/Source/VideoViewController.swift | 27 ++++++++++++++----- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ImageViewer/Source/GalleryItem.swift b/ImageViewer/Source/GalleryItem.swift index 2dfdbeae..c49c0ff6 100644 --- a/ImageViewer/Source/GalleryItem.swift +++ b/ImageViewer/Source/GalleryItem.swift @@ -7,14 +7,14 @@ // import UIKit +import AVFoundation public typealias ImageCompletion = (UIImage?) -> Void public typealias FetchImageBlock = (@escaping ImageCompletion) -> Void public typealias ItemViewControllerBlock = (_ index: Int, _ itemCount: Int, _ fetchImageBlock: FetchImageBlock, _ configuration: GalleryConfiguration, _ isInitialController: Bool) -> UIViewController public enum GalleryItem { - case image(fetchImageBlock: FetchImageBlock) - case video(fetchPreviewImageBlock: FetchImageBlock, videoURL: URL, videoProgress: Double) + case video(fetchPreviewImageBlock: FetchImageBlock, videoURL: URL, player: AVPlayer?, videoProgress: Double) case custom(fetchImageBlock: FetchImageBlock, itemViewControllerBlock: ItemViewControllerBlock) } diff --git a/ImageViewer/Source/GalleryPagingDataSource.swift b/ImageViewer/Source/GalleryPagingDataSource.swift index 63db9334..7d1c5d37 100644 --- a/ImageViewer/Source/GalleryPagingDataSource.swift +++ b/ImageViewer/Source/GalleryPagingDataSource.swift @@ -85,9 +85,9 @@ final class GalleryPagingDataSource: NSObject, UIPageViewControllerDataSource { return imageController - case .video(let fetchImageBlock, let videoURL, let videoProgress): + case .video(let fetchImageBlock, let videoURL, let player, let videoProgress): - let videoController = VideoViewController(index: itemIndex, itemCount: itemsDataSource.itemCount(), fetchImageBlock: fetchImageBlock, videoURL: videoURL, videoProgress: videoProgress, scrubber: scrubber, configuration: configuration, isInitialController: isInitial) + let videoController = VideoViewController(index: itemIndex, itemCount: itemsDataSource.itemCount(), fetchImageBlock: fetchImageBlock, videoURL: videoURL, player: player, videoProgress: videoProgress, scrubber: scrubber, configuration: configuration, isInitialController: isInitial) videoController.delegate = itemControllerDelegate videoController.displacedViewsDataSource = displacedViewsDataSource diff --git a/ImageViewer/Source/GalleryViewController.swift b/ImageViewer/Source/GalleryViewController.swift index 77850f3e..716ea080 100644 --- a/ImageViewer/Source/GalleryViewController.swift +++ b/ImageViewer/Source/GalleryViewController.swift @@ -689,11 +689,13 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate { case (_ as ImageViewController, let item as UIImageView): guard let image = item.image else { return } let activityVC = UIActivityViewController(activityItems: [image], applicationActivities: nil) + activityVC.excludedActivityTypes = [.copyToPasteboard] self.present(activityVC, animated: true) case (_ as VideoViewController, let item as VideoView): guard let videoUrl = ((item.player?.currentItem?.asset) as? AVURLAsset)?.url else { return } let activityVC = UIActivityViewController(activityItems: [videoUrl], applicationActivities: nil) + activityVC.excludedActivityTypes = [.copyToPasteboard] self.present(activityVC, animated: true) default: return diff --git a/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift b/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift index 1d6e1bd6..12dd064b 100644 --- a/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift +++ b/ImageViewer/Source/Thumbnails Controller/ThumbnailsViewController.swift @@ -116,7 +116,7 @@ class ThumbnailsViewController: UICollectionViewController, UICollectionViewDele } } - case .video(let fetchImageBlock, _, _): + case .video(let fetchImageBlock, _, _, _): fetchImageBlock() { image in diff --git a/ImageViewer/Source/VideoScrubber.swift b/ImageViewer/Source/VideoScrubber.swift index 409b303c..1bb26070 100644 --- a/ImageViewer/Source/VideoScrubber.swift +++ b/ImageViewer/Source/VideoScrubber.swift @@ -165,7 +165,6 @@ open class VideoScrubber: UIControl { } @objc func play() { - self.player?.play() } diff --git a/ImageViewer/Source/VideoViewController.swift b/ImageViewer/Source/VideoViewController.swift index 7ae65ce7..d3a91275 100644 --- a/ImageViewer/Source/VideoViewController.swift +++ b/ImageViewer/Source/VideoViewController.swift @@ -30,12 +30,12 @@ class VideoViewController: ItemBaseController { private var videoLayerGravity: AVLayerVideoGravity? = nil - init(index: Int, itemCount: Int, fetchImageBlock: @escaping FetchImageBlock, videoURL: URL, videoProgress: Double, scrubber: VideoScrubber, configuration: GalleryConfiguration, isInitialController: Bool = false) { + init(index: Int, itemCount: Int, fetchImageBlock: @escaping FetchImageBlock, videoURL: URL, player: AVPlayer?, videoProgress: Double, scrubber: VideoScrubber, configuration: GalleryConfiguration, isInitialController: Bool = false) { self.videoURL = videoURL - self.videoProgress = videoProgress + self.videoProgress = player == nil ? videoProgress : 0 self.scrubber = scrubber - self.player = AVPlayer(url: self.videoURL) + self.player = player ?? AVPlayer(url: videoURL) ///Only those options relevant to the paging VideoViewController are explicitly handled here, the rest is handled by ItemViewControllers for item in configuration { @@ -104,9 +104,20 @@ class VideoViewController: ItemBaseController { override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - - let isLandscape = itemView.bounds.width >= itemView.bounds.height - itemView.bounds.size = aspectFitSize(forContentOfSize: isLandscape ? fullHDScreenSizeLandscape : fullHDScreenSizePortrait, inBounds: self.scrollView.bounds.size) + + if itemView.bounds.width <= itemView.bounds.height + 10 && itemView.bounds.width >= itemView.bounds.height - 10 { + let minScale = min(scrollView.bounds.width, scrollView.bounds.height) + itemView.bounds.size = CGSize(width: minScale, height: minScale) + } else { + let isLandscape = itemView.bounds.width >= itemView.bounds.height + let ratio = itemView.bounds.width/itemView.bounds.height + let mainScreenRatio = isLandscape ? UIScreen.main.bounds.height/UIScreen.main.bounds.width : UIScreen.main.bounds.width/UIScreen.main.bounds.height + if (ratio > mainScreenRatio - 0.02 && ratio < mainScreenRatio + 0.02) { + itemView.bounds.size = aspectFitSize(forContentOfSize: isLandscape ? CGSize(width: UIScreen.main.bounds.height, height: UIScreen.main.bounds.width) : UIScreen.main.bounds.size, inBounds: self.scrollView.bounds.size) + } else { + itemView.bounds.size = aspectFitSize(forContentOfSize: isLandscape ? fullHDScreenSizeLandscape : fullHDScreenSizePortrait, inBounds: self.scrollView.bounds.size) + } + } itemView.center = scrollView.boundsCenter } @@ -225,7 +236,9 @@ class VideoViewController: ItemBaseController { autoPlayStarted = true embeddedPlayButton.isHidden = true - scrubber.player?.seek(to: CMTime(seconds: videoProgress, preferredTimescale: 1)) + if (videoProgress > 0) { + scrubber.player?.seek(to: CMTime(seconds: videoProgress, preferredTimescale: 1)) + } scrubber.play() } } From d8a40533916e46476cf957f2adf8cdf279af95ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gautier=20Ge=CC=81doux?= Date: Sat, 2 May 2020 11:49:26 +0200 Subject: [PATCH 6/6] clean --- ImageViewer/Source/VideoViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImageViewer/Source/VideoViewController.swift b/ImageViewer/Source/VideoViewController.swift index d3a91275..3e511a70 100644 --- a/ImageViewer/Source/VideoViewController.swift +++ b/ImageViewer/Source/VideoViewController.swift @@ -112,7 +112,7 @@ class VideoViewController: ItemBaseController { let isLandscape = itemView.bounds.width >= itemView.bounds.height let ratio = itemView.bounds.width/itemView.bounds.height let mainScreenRatio = isLandscape ? UIScreen.main.bounds.height/UIScreen.main.bounds.width : UIScreen.main.bounds.width/UIScreen.main.bounds.height - if (ratio > mainScreenRatio - 0.02 && ratio < mainScreenRatio + 0.02) { + if (ratio > mainScreenRatio - 0.05 && ratio < mainScreenRatio + 0.05) { itemView.bounds.size = aspectFitSize(forContentOfSize: isLandscape ? CGSize(width: UIScreen.main.bounds.height, height: UIScreen.main.bounds.width) : UIScreen.main.bounds.size, inBounds: self.scrollView.bounds.size) } else { itemView.bounds.size = aspectFitSize(forContentOfSize: isLandscape ? fullHDScreenSizeLandscape : fullHDScreenSizePortrait, inBounds: self.scrollView.bounds.size)