Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video support added. #437

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ var images = [SKPhoto]()
let photo = SKPhoto.photoWithImage(UIImage())// add some UIImage
images.append(photo)

// 2. create PhotoBrowser Instance, and present from your viewController.
// 2. for adding video
// Local file
if let url1 = Bundle.main.url(forResource: "bunny", withExtension: "mp4") {
images.append(SKPhoto.videoWithURL(url1))
}

// From internet
if let url2 = URL(string: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4") {
images.append(SKPhoto.videoWithURL(url2))
}

// 3. create PhotoBrowser Instance, and present from your viewController.
let browser = SKPhotoBrowser(photos: images)
browser.initializePageIndex(0)
present(browser, animated: true, completion: {})
Expand Down
8 changes: 8 additions & 0 deletions SKPhotoBrowser/SKLocalPhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ open class SKLocalPhoto: NSObject, SKPhotoProtocol {
open var shouldCachePhotoURLImage: Bool = false
open var caption: String?
open var index: Int = 0
public var videoURL: URL?

override init() {
super.init()
Expand Down Expand Up @@ -59,6 +60,13 @@ open class SKLocalPhoto: NSObject, SKPhotoProtocol {
NotificationCenter.default.post(name: Notification.Name(rawValue: SKPHOTO_LOADING_DID_END_NOTIFICATION), object: self)
}

// Check if we have a video URL
// https://github.com/engasix/

open func isVideo() -> Bool {
return self.videoURL != nil
}

// MARK: - class func
open class func photoWithImageURL(_ url: String) -> SKLocalPhoto {
return SKLocalPhoto(url: url)
Expand Down
20 changes: 14 additions & 6 deletions SKPhotoBrowser/SKPagingScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,21 @@ class SKPagingScrollView: UIScrollView {
continue
}

let page: SKZoomingScrollView = SKZoomingScrollView(frame: frame, browser: browser)
page.frame = frameForPageAtIndex(index)
page.tag = index + pageIndexTagOffset
let photo = browser.photos[index]

let page = SKZoomingScrollView(frame: frame, browser: browser)
page.photo = photo

if photo.isVideo() {
page.setupVideo()
} else {
page.setupImage()
}

page.frame = frameForPageAtIndex(photo.index)
page.tag = photo.index + pageIndexTagOffset
if let thumbnail = browser.animator.senderOriginImage,
index == browser.initPageIndex,
photo.index == browser.initPageIndex,
photo.underlyingImage == nil {
page.displayImage(thumbnail)
}
Expand All @@ -153,8 +161,8 @@ class SKPagingScrollView: UIScrollView {
addSubview(page)

// if exists caption, insert
if let captionView: SKCaptionView = createCaptionView(index) {
captionView.frame = frameForCaptionView(captionView, index: index)
if let captionView: SKCaptionView = createCaptionView(photo.index) {
captionView.frame = frameForCaptionView(captionView, index: photo.index)
captionView.alpha = browser.areControlsHidden() ? 0 : 1
addSubview(captionView)
// ref val for control
Expand Down
19 changes: 19 additions & 0 deletions SKPhotoBrowser/SKPhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ import SKPhotoBrowserObjC
var index: Int { get set }
var underlyingImage: UIImage! { get }
var caption: String? { get }
var videoURL: URL? { get }
var contentMode: UIView.ContentMode { get set }
func loadUnderlyingImageAndNotify()
func checkCache()
func isVideo () -> Bool
}

// MARK: - SKPhoto
open class SKPhoto: NSObject, SKPhotoProtocol {

open var index: Int = 0
open var underlyingImage: UIImage!
open var caption: String?
open var contentMode: UIView.ContentMode = .scaleAspectFill
open var shouldCachePhotoURLImage: Bool = false
open var photoURL: String!
open var videoURL: URL?

override init() {
super.init()
Expand All @@ -49,6 +53,11 @@ open class SKPhoto: NSObject, SKPhotoProtocol {
underlyingImage = holder
}

convenience init(videoURL: URL?) {
self.init()
self.videoURL = videoURL
}

open func checkCache() {
guard let photoURL = photoURL else {
return
Expand Down Expand Up @@ -129,6 +138,12 @@ open class SKPhoto: NSObject, SKPhotoProtocol {
NotificationCenter.default.post(name: Notification.Name(rawValue: SKPHOTO_LOADING_DID_END_NOTIFICATION), object: self)
}

// Check if we have a video URL
// https://github.com/engasix/

open func isVideo() -> Bool {
return self.videoURL != nil
}
}

// MARK: - Static Function
Expand All @@ -145,4 +160,8 @@ extension SKPhoto {
public static func photoWithImageURL(_ url: String, holder: UIImage?) -> SKPhoto {
return SKPhoto(url: url, holder: holder)
}

public static func videoWithURL(_ url: URL) -> SKPhoto {
return SKPhoto(videoURL: url)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions SKPhotoBrowser/SKPhotoBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ open class SKPhotoBrowser: UIViewController {
// MARK: - override
override open func viewDidLoad() {
super.viewDidLoad()
configureAppearance()
configurePagingScrollView()
configureGestureControl()
configureActionView()
configurePaginationView()
configureToolbar()
configureAppearance()
configurePagingScrollView()
configureGestureControl()
configureActionView()
configurePaginationView()
configureToolbar()

animator.willPresent(self)
}
Expand Down
Loading