Skip to content

Commit

Permalink
优化mac下的ui
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Jan 13, 2024
1 parent f2eba9e commit f3995c2
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions Sources/KSPlayer/SwiftUI/KSVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,40 @@ public struct KSVideoPlayerView: View {
self.subtitleDataSouce = subtitleDataSouce
}

public var body: some View {
ZStack {
playView
VideoSubtitleView(model: playerCoordinator.subtitleModel)
#if os(macOS)
controllerView.opacity(playerCoordinator.isMaskShow ? 1 : 0)
#else
if playerCoordinator.isMaskShow {
controllerView
}
#endif
}
.preferredColorScheme(.dark)
.tint(.white)
.persistentSystemOverlays(.hidden)
.toolbar(.hidden, for: .automatic)
#if os(tvOS)
.onPlayPauseCommand {
if playerCoordinator.state.isPlaying {
playerCoordinator.playerLayer?.pause()
} else {
playerCoordinator.playerLayer?.play()
}
}
.onExitCommand {
if playerCoordinator.isMaskShow {
playerCoordinator.isMaskShow = false
} else {
dismiss()
}
}
#endif
}

private var playView: some View {
KSVideoPlayer(coordinator: playerCoordinator, url: url, options: options)
.onStateChanged { playerLayer, state in
Expand Down Expand Up @@ -169,36 +203,6 @@ public struct KSVideoPlayerView: View {
.padding()
}

public var body: some View {
ZStack {
playView
VideoSubtitleView(model: playerCoordinator.subtitleModel)
if playerCoordinator.isMaskShow {
controllerView
}
}
.preferredColorScheme(.dark)
.tint(.white)
.persistentSystemOverlays(.hidden)
.toolbar(.hidden, for: .automatic)
#if os(tvOS)
.onPlayPauseCommand {
if playerCoordinator.state.isPlaying {
playerCoordinator.playerLayer?.pause()
} else {
playerCoordinator.playerLayer?.play()
}
}
.onExitCommand {
if playerCoordinator.isMaskShow {
playerCoordinator.isMaskShow = false
} else {
dismiss()
}
}
#endif
}

fileprivate enum FocusableField {
case play, controller
}
Expand Down Expand Up @@ -365,7 +369,7 @@ struct VideoControllerView: View {
infoButton
// iOS 模拟器加keyboardShortcut会导致KSVideoPlayer.Coordinator无法释放。真机不会有这个问题
#if !os(tvOS)
.keyboardShortcut("s", modifiers: [.command, .shift])
.keyboardShortcut("i", modifiers: [.command])
#endif
}
#endif
Expand Down

0 comments on commit f3995c2

Please sign in to comment.