Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
feature: stream play video
Browse files Browse the repository at this point in the history
  • Loading branch information
wzxha authored and suricforever committed Aug 29, 2018
1 parent eb1be3f commit 306717a
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 67 deletions.
10 changes: 7 additions & 3 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = Teambition;
TargetAttributes = {
4A6BC7871C76F8C500DACDA5 = {
Expand Down Expand Up @@ -222,12 +222,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -254,7 +256,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -275,12 +277,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -301,7 +305,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
2 changes: 1 addition & 1 deletion Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ViewController: UIViewController {

// mp4

let mp4 = URL(string: "https://tcs.teambition.net/storage/1013eff73697f68b5e981613debcdcf9673b?download=49DCA8D7-ADD7-487D-83E2-C414D6F9AE23.mp4&Signature=eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6Ii9zdG9yYWdlLzEwMTNlZmY3MzY5N2Y2OGI1ZTk4MTYxM2RlYmNkY2Y5NjczYiIsImV4cCI6MTUyMTY3NjgwMH0.lqC5zkN-URLa7QxvMpRu78O-4HMvicacIRTVClfnYKI")!
let mp4 = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")!
let mp4Item = FilePreviewItem(previewItemURL: mp4, previewItemTitle: "49DCA8D7-ADD7-487D-83E2-C414D6F9AE23.mp4", fileExtension: "mp4", fileKey: "1013eff73697f68b5e981613debcdcf9673b")

// .key
Expand Down
4 changes: 2 additions & 2 deletions FilePreviewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -290,7 +290,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "0940"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
114 changes: 75 additions & 39 deletions FilePreviewController/FPAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ var AssociatedObjectHandle: UInt8 = 0

public extension UIViewController {
public func presentFilePreviewController(viewControllerToPresent controller: UIViewController, fromView: UIView?) {
if let fromView = fromView {
let transitionDelegate = TransitionDelegate(fromView: fromView)
controller.transitioningDelegate = transitionDelegate
controller.fp_transitionDelegate = transitionDelegate
}
let transitionDelegate = TransitionDelegate(fromView: fromView)
controller.transitioningDelegate = transitionDelegate
controller.fp_transitionDelegate = transitionDelegate
present(controller, animated: true, completion: nil)
}

Expand All @@ -42,7 +40,7 @@ public extension UIViewController {
open class TransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
open var fromView: UIView?

init(fromView: UIView) {
init(fromView: UIView?) {
super.init()
self.fromView = fromView
}
Expand All @@ -63,8 +61,8 @@ open class TransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
}

open class PresentAnimation: NSObject, UIViewControllerAnimatedTransitioning {
var fromView: UIView!
public init(fromView: UIView) {
var fromView: UIView?
public init(fromView: UIView?) {
super.init()
self.fromView = fromView
}
Expand All @@ -75,29 +73,43 @@ open class PresentAnimation: NSObject, UIViewControllerAnimatedTransitioning {

open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let container = transitionContext.containerView
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!

container.addSubview(toVC.view)
let fromFrame = container.convert(fromView.frame, from: fromView.superview)
let toFrame = transitionContext.finalFrame(for: toVC)

let scale = CGAffineTransform(scaleX: fromFrame.width/toFrame.width, y: fromFrame.height/toFrame.height)
let translation = CGAffineTransform(translationX: fromFrame.midX - toFrame.midX, y: fromFrame.midY - toFrame.midY)
toVC.view.transform = scale.concatenating(translation)
toVC.view.alpha = 0

UIView.animate(withDuration: PresentDuration, delay: 0, options: UIViewAnimationOptions(), animations: {
toVC.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
toVC.view.alpha = 1
guard let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) else {
return
}
if let fromView = fromView {
container.addSubview(toViewController.view)
let fromFrame = container.convert(fromView.frame, from: fromView.superview)
let toFrame = transitionContext.finalFrame(for: toViewController)

let scale = CGAffineTransform(scaleX: fromFrame.width/toFrame.width, y: fromFrame.height/toFrame.height)
let translation = CGAffineTransform(translationX: fromFrame.midX - toFrame.midX, y: fromFrame.midY - toFrame.midY)
toViewController.view.transform = scale.concatenating(translation)
toViewController.view.alpha = 0

UIView.animate(withDuration: PresentDuration, delay: 0, options: UIViewAnimationOptions(), animations: {
toViewController.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
toViewController.view.alpha = 1
}) { (_) in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
} else {
var frame = fromViewController.view.frame
frame.origin.y = frame.size.height
toViewController.view.frame = frame
container.addSubview(toViewController.view)
UIView.animate(withDuration: PresentDuration, delay: 0, options: .curveEaseIn, animations: {
toViewController.view.frame = fromViewController.view.frame
}) { (_) in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
}
}

open class DismissAnimation: NSObject, UIViewControllerAnimatedTransitioning {
var toView: UIView!
public init(toView: UIView) {
var toView: UIView?
public init(toView: UIView?) {
super.init()
self.toView = toView
}
Expand All @@ -108,23 +120,47 @@ open class DismissAnimation: NSObject, UIViewControllerAnimatedTransitioning {

open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let container = transitionContext.containerView
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!

toVC.view.frame = transitionContext.finalFrame(for: toVC)
container.addSubview(toVC.view)
container.addSubview(fromVC.view)
let toFrame = container.convert(toView.frame, from: toView.superview)
let fromFrame = transitionContext.finalFrame(for: fromVC)

let scale = CGAffineTransform(scaleX: toFrame.width/fromFrame.width, y: toFrame.height/fromFrame.height)
let translation = CGAffineTransform(translationX: toFrame.midX - fromFrame.midX, y: toFrame.midY - fromFrame.midY)
UIView.animate(withDuration: DismissDuration, delay: 0, options: .curveEaseOut, animations: {
fromVC.view.alpha = 0
fromVC.view.transform = scale.concatenating(translation)
guard let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) else {
return
}

func willDismiss() {
if let navigationViewController = fromViewController as? UINavigationController,
let filePreviewController = navigationViewController.viewControllers.last as? FilePreviewController {
filePreviewController.willDismiss()
} else {
(fromViewController as? FilePreviewController)?.willDismiss()
}
}

if let toView = toView {
toViewController.view.frame = transitionContext.finalFrame(for: toViewController)
container.addSubview(toViewController.view)
container.addSubview(fromViewController.view)
let toFrame = container.convert(toView.frame, from: toView.superview)
let fromFrame = transitionContext.finalFrame(for: fromViewController)

let scale = CGAffineTransform(scaleX: toFrame.width/fromFrame.width, y: toFrame.height/fromFrame.height)
let translation = CGAffineTransform(translationX: toFrame.midX - fromFrame.midX, y: toFrame.midY - fromFrame.midY)
UIView.animate(withDuration: DismissDuration, delay: 0, options: .curveEaseOut, animations: {
fromViewController.view.alpha = 0
fromViewController.view.transform = scale.concatenating(translation)
}) { (_) in
willDismiss()
fromViewController.view.removeFromSuperview()
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
} else {
var frame = fromViewController.view.frame
frame.origin.y = frame.size.height
UIView.animate(withDuration: DismissDuration, delay: 0, options: .curveEaseIn, animations: {
fromViewController.view.frame = frame
}) { (_) in
fromVC.view.removeFromSuperview()
willDismiss()
fromViewController.view.removeFromSuperview()
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
}
}
13 changes: 6 additions & 7 deletions FilePreviewController/FilePreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import QuickLook
import Alamofire
import UIKit

fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
Expand Down Expand Up @@ -140,7 +141,7 @@ open class FilePreviewController: QLPreviewController {
progressView.tintColor = UIColor.blue
return progressView
}()
fileprivate var shouldDisplayToolbar: Bool {
var shouldDisplayToolbar: Bool {
get {
return items?.count > 0
}
Expand Down Expand Up @@ -279,11 +280,7 @@ open class FilePreviewController: QLPreviewController {
customNavigationBar = customHeaderView
}
}

open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}


deinit {
if let navigationBar = navigationBar {
navigationBar.removeObserver(self, forKeyPath: "center")
Expand Down Expand Up @@ -328,13 +325,13 @@ open class FilePreviewController: QLPreviewController {
self.view.layoutIfNeeded()
self.navigationBar?.superview?.layoutIfNeeded()
self.originalToolbar?.isHidden = true
self.navigationBar?.superview?.bringSubview(toFront: self.customNavigationBar!)
}, completion: { (_) in
self.originalToolbar?.isHidden = true
DispatchQueue.main.async {
self.navigationBar?.superview?.bringSubview(toFront: self.customNavigationBar!)
}
})

}
setNeedsStatusBarAppearanceUpdate()
}
Expand All @@ -350,6 +347,8 @@ open class FilePreviewController: QLPreviewController {
presentingViewController?.dismissFilePreviewController()
}

func willDismiss() {}

func getNavigationBar(fromView view: UIView) -> UINavigationBar? {
for v in view.subviews {
if v is UINavigationBar {
Expand Down
Loading

0 comments on commit 306717a

Please sign in to comment.