Skip to content

Commit

Permalink
退出的时候,playerLayer可能为空了。所以改成用timemodel
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Dec 3, 2023
1 parent 58b46dd commit 479f658
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
11 changes: 1 addition & 10 deletions Demo/SwiftUI/Shared/MovieModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,6 @@ extension KSVideoPlayerView {
}
playmodel.save()
model.save()
self.init(url: url, options: options, title: model.name) { layer in
if let layer {
playmodel.duration = Int16(layer.player.duration)
if playmodel.duration > 0 {
playmodel.current = Int16(layer.player.currentPlaybackTime)
}
playmodel.save()
model.save()
}
}
self.init(url: url, options: options, title: model.name)
}
}
7 changes: 4 additions & 3 deletions Sources/KSPlayer/SwiftUI/KSVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
public struct KSVideoPlayerView: View {
private let subtitleDataSouce: SubtitleDataSouce?
private let onPlayerDisappear: ((KSPlayerLayer?) -> Void)?
private let onPlayerDisappear: ((ControllerTimeModel) -> Void)?
@State
private var title: String
@State
Expand All @@ -32,7 +32,7 @@ public struct KSVideoPlayerView: View {
}
}

public init(url: URL, options: KSOptions, title: String? = nil, subtitleDataSouce: SubtitleDataSouce? = nil, onPlayerDisappear: ((KSPlayerLayer?) -> Void)? = nil) {
public init(url: URL, options: KSOptions, title: String? = nil, subtitleDataSouce: SubtitleDataSouce? = nil, onPlayerDisappear: ((ControllerTimeModel) -> Void)? = nil) {
_url = .init(initialValue: url)
_title = .init(initialValue: title ?? url.lastPathComponent)
#if os(macOS)
Expand Down Expand Up @@ -140,7 +140,8 @@ public struct KSVideoPlayerView: View {
// #endif
}
.onDisappear {
onPlayerDisappear?(playerCoordinator.playerLayer)
// 在tvos,playerLayer已经为空了。所以改成用timemodel
onPlayerDisappear?(playerCoordinator.timemodel)
}
.preferredColorScheme(.dark)
.tint(.white)
Expand Down

0 comments on commit 479f658

Please sign in to comment.