Skip to content

Commit

Permalink
add onKeyPress
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Oct 19, 2023
1 parent d9d1462 commit c63a38a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion FFmpegKit
60 changes: 41 additions & 19 deletions Sources/KSPlayer/SwiftUI/KSVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,26 @@ public struct KSVideoPlayerView: View {
.tint(.white)
.persistentSystemOverlays(.hidden)
.toolbar(isMaskShow ? .visible : .hidden, for: .automatic)
// .onKeyPress(.leftArrow) {
// playerCoordinator.skip(interval: -15)
// return .handled
// }
// .onKeyPress(.rightArrow) {
// playerCoordinator.skip(interval: 15)
// return .handled
// }
.onKeyPressLeftArrow {
playerCoordinator.skip(interval: -15)
}
.onKeyPressRightArrow {
playerCoordinator.skip(interval: 15)
}
#if os(macOS)
.onTapGesture(count: 2) {
guard let view = playerCoordinator.playerLayer else {
return
}
view.window?.toggleFullScreen(nil)
view.needsLayout = true
view.layoutSubtreeIfNeeded()
}
.onExitCommand {
playerCoordinator.playerLayer?.exitFullScreenMode()
.onTapGesture(count: 2) {
guard let view = playerCoordinator.playerLayer else {
return
}
view.window?.toggleFullScreen(nil)
view.needsLayout = true
view.layoutSubtreeIfNeeded()
}
.onExitCommand {
playerCoordinator.playerLayer?.exitFullScreenMode()
}
#else
.onTapGesture {
.onTapGesture {
isMaskShow.toggle()
}
#endif
Expand Down Expand Up @@ -252,6 +250,30 @@ public struct KSVideoPlayerView: View {
}
}

extension View {
func onKeyPressLeftArrow(action: @escaping () -> Void) -> some View {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
return onKeyPress(.leftArrow) {
action()
return .handled
}
} else {
return self
}
}

func onKeyPressRightArrow(action: @escaping () -> Void) -> some View {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
return onKeyPress(.rightArrow) {
action()
return .handled
}
} else {
return self
}
}
}

@available(iOS 15, tvOS 16, macOS 12, *)
struct VideoControllerView: View {
@ObservedObject
Expand Down

0 comments on commit c63a38a

Please sign in to comment.