|
@@ -2,10 +2,10 @@ import UIKit
|
|
|
import CoreVideo
|
|
import CoreVideo
|
|
|
import Metal
|
|
import Metal
|
|
|
|
|
|
|
|
-private let lnDefaultFPS = kQGHWDMP4DefaultFPS
|
|
|
|
|
-private let lnMinFPS = 1
|
|
|
|
|
-private let lnMaxFPS = 60
|
|
|
|
|
-private let lnMaxCompatibleVAPVersion = 2
|
|
|
|
|
|
|
+private let lnDefaultFPS = kLNMP4DefaultFPS
|
|
|
|
|
+private let lnMinFPS = kLNMP4MinFPS
|
|
|
|
|
+private let lnMaxFPS = LNMP4MaxFPS
|
|
|
|
|
+private let lnMaxCompatibleVAPVersion = LNVAPMaxCompatibleVersion
|
|
|
|
|
|
|
|
@objcMembers
|
|
@objcMembers
|
|
|
public final class LNVAPPlayerView: UIView {
|
|
public final class LNVAPPlayerView: UIView {
|
|
@@ -15,7 +15,6 @@ public final class LNVAPPlayerView: UIView {
|
|
|
fileprivate var didStart = false
|
|
fileprivate var didStart = false
|
|
|
|
|
|
|
|
public weak var delegate: LNVAPPlaybackDelegate?
|
|
public weak var delegate: LNVAPPlaybackDelegate?
|
|
|
- public weak var legacyDelegate: LNVAPLegacyPlaybackDelegate?
|
|
|
|
|
|
|
|
|
|
public var enterBackgroundOperation: LNEnterBackgroundOperation {
|
|
public var enterBackgroundOperation: LNEnterBackgroundOperation {
|
|
|
get { core.enterBackgroundOperation }
|
|
get { core.enterBackgroundOperation }
|
|
@@ -156,49 +155,29 @@ public final class LNVAPPlayerView: UIView {
|
|
|
playbackView.isUserInteractionEnabled = true
|
|
playbackView.isUserInteractionEnabled = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @objc(addVapTapGesture:)
|
|
|
|
|
- public func addVapTapGesture(_ handler: @escaping LNVAPGestureEventBlock) {
|
|
|
|
|
- lnAddVapTapGesture(handler)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @objc(addVapGesture:callback:)
|
|
|
|
|
- public func addVapGesture(_ gestureRecognizer: UIGestureRecognizer, callback: @escaping LNVAPGestureEventBlock) {
|
|
|
|
|
- lnAddVapGesture(gestureRecognizer, callback: callback)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
fileprivate func notifyShouldStart(_ config: LNVAPConfigModel) -> Bool {
|
|
fileprivate func notifyShouldStart(_ config: LNVAPConfigModel) -> Bool {
|
|
|
- if let allow = delegate?.lnPlayerShouldStart?(self, config: config) {
|
|
|
|
|
- return allow
|
|
|
|
|
- }
|
|
|
|
|
- return legacyDelegate?.shouldStartPlayMP4?(self, config: config) ?? true
|
|
|
|
|
|
|
+ delegate?.lnPlayerShouldStart?(self, config: config) ?? true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fileprivate func notifyStart() {
|
|
fileprivate func notifyStart() {
|
|
|
didStart = true
|
|
didStart = true
|
|
|
delegate?.lnPlayerDidStart?(self)
|
|
delegate?.lnPlayerDidStart?(self)
|
|
|
- legacyDelegate?.viewDidStartPlayMP4?(self)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fileprivate func notifyPlay(_ frame: LNMP4AnimatedImageFrame) {
|
|
fileprivate func notifyPlay(_ frame: LNMP4AnimatedImageFrame) {
|
|
|
delegate?.lnPlayerDidPlay?(self, frame: frame)
|
|
delegate?.lnPlayerDidPlay?(self, frame: frame)
|
|
|
- legacyDelegate?.viewDidPlayMP4AtFrame?(frame, view: self)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fileprivate func notifyFinish(_ totalFrameCount: Int) {
|
|
fileprivate func notifyFinish(_ totalFrameCount: Int) {
|
|
|
delegate?.lnPlayerDidFinish?(self, totalFrameCount: totalFrameCount)
|
|
delegate?.lnPlayerDidFinish?(self, totalFrameCount: totalFrameCount)
|
|
|
- legacyDelegate?.viewDidFinishPlayMP4?(totalFrameCount, view: self)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fileprivate func notifyFail(_ error: NSError) {
|
|
fileprivate func notifyFail(_ error: NSError) {
|
|
|
delegate?.lnPlayerDidFail?(self, error: error)
|
|
delegate?.lnPlayerDidFail?(self, error: error)
|
|
|
- legacyDelegate?.viewDidFailPlayMP4?(error)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fileprivate func contentForTag(_ tag: String, resource: LNVAPSourceInfo) -> String? {
|
|
fileprivate func contentForTag(_ tag: String, resource: LNVAPSourceInfo) -> String? {
|
|
|
- if let text = delegate?.lnPlayerContent?(forTag: tag, resource: resource) {
|
|
|
|
|
- return text
|
|
|
|
|
- }
|
|
|
|
|
- return legacyDelegate?.contentForVapTag?(tag, resource: resource)
|
|
|
|
|
|
|
+ delegate?.lnPlayerContent?(forTag: tag, resource: resource)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fileprivate func loadImage(withURL url: String, context: NSDictionary, completion: @escaping LNVAPImageCompletion) {
|
|
fileprivate func loadImage(withURL url: String, context: NSDictionary, completion: @escaping LNVAPImageCompletion) {
|
|
@@ -206,10 +185,6 @@ public final class LNVAPPlayerView: UIView {
|
|
|
handler(url, context, completion)
|
|
handler(url, context, completion)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if (legacyDelegate as AnyObject?)?.responds(to: #selector(LNVAPLegacyPlaybackDelegate.loadVapImage(withURL:context:completion:))) == true {
|
|
|
|
|
- legacyDelegate?.loadVapImage?(withURL: url, context: context, completion: completion)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
let error = NSError(
|
|
let error = NSError(
|
|
|
domain: NSURLErrorDomain,
|
|
domain: NSURLErrorDomain,
|
|
|
code: -1,
|
|
code: -1,
|
|
@@ -220,7 +195,6 @@ public final class LNVAPPlayerView: UIView {
|
|
|
|
|
|
|
|
fileprivate func notifyStopIfNeeded(lastFrameIndex: Int) {
|
|
fileprivate func notifyStopIfNeeded(lastFrameIndex: Int) {
|
|
|
delegate?.lnPlayerDidStop?(self)
|
|
delegate?.lnPlayerDidStop?(self)
|
|
|
- legacyDelegate?.viewDidStopPlayMP4?(lastFrameIndex, view: self)
|
|
|
|
|
didStart = false
|
|
didStart = false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -374,7 +348,7 @@ private final class LNPlayerCore: NSObject {
|
|
|
self.filePath = filePath
|
|
self.filePath = filePath
|
|
|
self.repeatCount = repeatCount
|
|
self.repeatCount = repeatCount
|
|
|
|
|
|
|
|
- if callbackQueue == nil, (owner?.delegate != nil || owner?.legacyDelegate != nil) {
|
|
|
|
|
|
|
+ if callbackQueue == nil, owner?.delegate != nil {
|
|
|
let queue = OperationQueue()
|
|
let queue = OperationQueue()
|
|
|
queue.maxConcurrentOperationCount = 1
|
|
queue.maxConcurrentOperationCount = 1
|
|
|
callbackQueue = queue
|
|
callbackQueue = queue
|
|
@@ -700,7 +674,7 @@ extension LNPlayerCore: LNAnimatedImageDecoderDelegate {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func decoderDidFailDecode(_ decoder: LNBaseDecoder?, error: NSError) {
|
|
func decoderDidFailDecode(_ decoder: LNBaseDecoder?, error: NSError) {
|
|
|
- // Keep parity with OC UIView+VAP: stop first, then emit failure callback.
|
|
|
|
|
|
|
+ // Stop first, then emit the failure callback to keep playback state consistent.
|
|
|
stopInternal(triggerDelegate: true)
|
|
stopInternal(triggerDelegate: true)
|
|
|
performCallback { [weak self] in
|
|
performCallback { [weak self] in
|
|
|
self?.owner?.notifyFail(error)
|
|
self?.owner?.notifyFail(error)
|