Skip to content

Commit

Permalink
回调函数改成public
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Jan 5, 2024
1 parent 5641049 commit b6c35d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Sources/KSPlayer/AVPlayer/KSOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ open class KSOptions {
public var hardwareDecode = KSOptions.hardwareDecode
public var asynchronousDecompression = KSOptions.asynchronousDecompression
public var videoDisable = false
public var canStartPictureInPictureAutomaticallyFromInline = true
public var canStartPictureInPictureAutomaticallyFromInline = KSOptions.canStartPictureInPictureAutomaticallyFromInline
public var automaticWindowResize = true
@Published
public var videoInterlacingType: VideoInterlacingType?
Expand Down Expand Up @@ -464,6 +464,7 @@ public extension KSOptions {
// 默认不用自研的硬解,因为有些视频的AVPacket的pts顺序是不对的,只有解码后的AVFrame里面的pts是对的。
static var asynchronousDecompression = false
static var isPipPopViewController = false
static var canStartPictureInPictureAutomaticallyFromInline = true
static var displayCriteriaFormatDescriptionEnabled = false
/// 日志级别
static var logLevel = LogLevel.warning
Expand Down
8 changes: 4 additions & 4 deletions Sources/KSPlayer/AVPlayer/KSVideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ extension KSVideoPlayer: UIViewRepresentable {
}

private var delayItem: DispatchWorkItem?
fileprivate var onPlay: ((TimeInterval, TimeInterval) -> Void)?
fileprivate var onFinish: ((KSPlayerLayer, Error?) -> Void)?
fileprivate var onStateChanged: ((KSPlayerLayer, KSPlayerState) -> Void)?
fileprivate var onBufferChanged: ((Int, TimeInterval) -> Void)?
public var onPlay: ((TimeInterval, TimeInterval) -> Void)?
public var onFinish: ((KSPlayerLayer, Error?) -> Void)?
public var onStateChanged: ((KSPlayerLayer, KSPlayerState) -> Void)?
public var onBufferChanged: ((Int, TimeInterval) -> Void)?
#if canImport(UIKit)
fileprivate var onSwipe: ((UISwipeGestureRecognizer.Direction) -> Void)?
@objc fileprivate func swipeGestureAction(_ recognizer: UISwipeGestureRecognizer) {
Expand Down
11 changes: 3 additions & 8 deletions Sources/KSPlayer/SwiftUI/KSVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import SwiftUI
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
public struct KSVideoPlayerView: View {
private let subtitleDataSouce: SubtitleDataSouce?
private let onPlayerDisappear: ((ControllerTimeModel) -> Void)?
@State
private var title: String
@StateObject
private var playerCoordinator = KSVideoPlayer.Coordinator()
private var playerCoordinator: KSVideoPlayer.Coordinator
@Environment(\.dismiss)
private var dismiss
public let options: KSOptions
Expand All @@ -28,15 +27,15 @@ public struct KSVideoPlayerView: View {
}
}

public init(url: URL, options: KSOptions, title: String? = nil, subtitleDataSouce: SubtitleDataSouce? = nil, onPlayerDisappear: ((ControllerTimeModel) -> Void)? = nil) {
public init(coordinator: KSVideoPlayer.Coordinator = KSVideoPlayer.Coordinator(), url: URL, options: KSOptions, title: String? = nil, subtitleDataSouce: SubtitleDataSouce? = nil) {
_url = .init(initialValue: url)
_playerCoordinator = .init(wrappedValue: coordinator)
_title = .init(initialValue: title ?? url.lastPathComponent)
#if os(macOS)
NSDocumentController.shared.noteNewRecentDocumentURL(url)
#endif
self.options = options
self.subtitleDataSouce = subtitleDataSouce
self.onPlayerDisappear = onPlayerDisappear
}

public var body: some View {
Expand Down Expand Up @@ -90,10 +89,6 @@ public struct KSVideoPlayerView: View {
// }
// #endif
}
.onDisappear {
// 在tvos,playerLayer已经为空了。所以改成用timemodel
onPlayerDisappear?(playerCoordinator.timemodel)
}
.preferredColorScheme(.dark)
.tint(.white)
.persistentSystemOverlays(.hidden)
Expand Down

0 comments on commit b6c35d6

Please sign in to comment.