Skip to content

Commit

Permalink
fix #581
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Oct 15, 2023
1 parent 58838b6 commit 7876fbb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion FFmpegKit
3 changes: 2 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public protocol PlayerControllerDelegate: class {
open class KSOptions {
// public static let shared = KSOptions()
/// 最低缓存视频时间
@Published public var preferredForwardBufferDuration = KSOptions.preferredForwardBufferDuration
@Published
public var preferredForwardBufferDuration = KSOptions.preferredForwardBufferDuration
/// 最大缓存视频时间
public var maxBufferDuration = KSOptions.maxBufferDuration
/// 是否开启秒开
Expand Down
34 changes: 22 additions & 12 deletions Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ open class KSOptions {
public var videoDisable = false
public var canStartPictureInPictureAutomaticallyFromInline = true
public var automaticWindowResize = true
@Published
public var videoInterlacingType: VideoInterlacingType?
private var videoClockDelayCount = 0

public internal(set) var formatName = ""
Expand Down Expand Up @@ -249,15 +251,6 @@ open class KSOptions {
display == .plane
}

private var idetTypeMap = [VideoInterlacingType: Int]()
@Published public var videoInterlacingType: VideoInterlacingType?
public enum VideoInterlacingType: String {
case tff
case bff
case progressive
case undetermined
}

open func io(log: String) {
if log.starts(with: "Original list of addresses"), dnsStartTime == 0 {
dnsStartTime = CACurrentMediaTime()
Expand All @@ -268,6 +261,7 @@ open class KSOptions {
}
}

private var idetTypeMap = [VideoInterlacingType: Int]()
open func filter(log: String) {
if log.starts(with: "Repeated Field:") {
log.split(separator: ",").forEach { str in
Expand Down Expand Up @@ -403,6 +397,19 @@ open class KSOptions {
#endif
return cotentRange
}

open func playerLayerDeinit() {
#if os(tvOS) || os(xrOS)
UIApplication.shared.windows.first?.avDisplayManager.preferredDisplayCriteria = nil
#endif
}
}

public enum VideoInterlacingType: String {
case tff
case bff
case progressive
case undetermined
}

public extension KSOptions {
Expand Down Expand Up @@ -575,18 +582,21 @@ public class FileLog: LogHandler {
}
}

@inlinable public func KSLog(_ error: @autoclosure () -> Error, file: String = #file, function: String = #function, line: UInt = #line) {
@inlinable
public func KSLog(_ error: @autoclosure () -> Error, file: String = #file, function: String = #function, line: UInt = #line) {
KSLog(level: .error, error().localizedDescription, file: file, function: function, line: line)
}

@inlinable public func KSLog(level: LogLevel = .warning, _ message: @autoclosure () -> CustomStringConvertible, file: String = #file, function: String = #function, line: UInt = #line) {
@inlinable
public func KSLog(level: LogLevel = .warning, _ message: @autoclosure () -> CustomStringConvertible, file: String = #file, function: String = #function, line: UInt = #line) {
if level.rawValue <= KSOptions.logLevel.rawValue {
let fileName = (file as NSString).lastPathComponent
KSOptions.logger.log(level: level, message: message(), file: fileName, function: function, line: line)
}
}

@inlinable public func KSLog(level: LogLevel = .warning, dso: UnsafeRawPointer = #dsohandle, _ message: StaticString, _ args: CVarArg...) {
@inlinable
public func KSLog(level: LogLevel = .warning, dso: UnsafeRawPointer = #dsohandle, _ message: StaticString, _ args: CVarArg...) {
if level.rawValue <= KSOptions.logLevel.rawValue {
os_log(level.logType, dso: dso, message, args)
}
Expand Down
13 changes: 7 additions & 6 deletions Sources/KSPlayer/AVPlayer/KSPlayerLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public protocol KSPlayerLayerDelegate: AnyObject {

open class KSPlayerLayer: UIView {
public weak var delegate: KSPlayerLayerDelegate?
@Published public var bufferingProgress: Int = 0
@Published public var loopCount: Int = 0
@Published public var isPipActive = false {
@Published
public var bufferingProgress: Int = 0
@Published
public var loopCount: Int = 0
@Published
public var isPipActive = false {
didSet {
if #available(tvOS 14.0, *) {
guard let pipController = player.pipController else {
Expand Down Expand Up @@ -206,9 +209,7 @@ open class KSPlayerLayer: UIView {
}
NotificationCenter.default.removeObserver(self)
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
#if os(tvOS) || os(xrOS)
UIApplication.shared.windows.first?.avDisplayManager.preferredDisplayCriteria = nil
#endif
options.playerLayerDeinit()
}

public func set(url: URL, options: KSOptions) {
Expand Down
6 changes: 4 additions & 2 deletions Sources/KSPlayer/AVPlayer/KSVideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ extension View {
/// 这是一个频繁变化的model。View要少用这个
public class ControllerTimeModel: ObservableObject {
// 改成int才不会频繁更新
@Published public var currentTime = 0
@Published public var totalTime = 1
@Published
public var currentTime = 0
@Published
public var totalTime = 1
}
3 changes: 2 additions & 1 deletion Sources/KSPlayer/MEPlayer/CircularBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public class CircularBuffer<Item: ObjectQueueItem> {

extension FixedWidthInteger {
/// Returns the next power of two.
@inline(__always) func nextPowerOf2() -> Self {
@inline(__always)
func nextPowerOf2() -> Self {
guard self != 0 else {
return 1
}
Expand Down

0 comments on commit 7876fbb

Please sign in to comment.