Skip to content

Commit

Permalink
fix macos build
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Feb 8, 2025
1 parent 5e6e217 commit c8d1b3a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ on:
jobs:
buidJob:
name: buid
runs-on: macos-14
runs-on: macos-latest
steps:
- uses: actions/checkout@main
with:
submodules: recursive
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode
- name: Set up Xcode
run: |
sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer
sudo xcode-select -s /Applications/Xcode_16.1.app/Contents/Developer
xcode-select -p
xcodebuild -version
- name: Build
run: |
swift build
swift build --sdk `xcrun -sdk iphonesimulator -show-sdk-path` -Xswiftc -target -Xswiftc x86_64-apple-ios13.0-simulator
swift build --sdk `xcrun -sdk appletvsimulator -show-sdk-path` -Xswiftc -target -Xswiftc x86_64-apple-tvos13.0-simulator
swift build --sdk `xcrun -sdk xrsimulator -show-sdk-path` -Xswiftc -target -Xswiftc x86_64-apple-xros1.0-simulator
- name: Build macOS
run: swift build
- name: Build iOS
run: swift build --sdk `xcrun -sdk iphonesimulator -show-sdk-path` -Xswiftc -target -Xswiftc x86_64-apple-ios13.0-simulator
- name: Build tvOS
run: swift build --sdk `xcrun -sdk appletvsimulator -show-sdk-path` -Xswiftc -target -Xswiftc x86_64-apple-tvos13.0-simulator
- name: Build xrOS
run: swift build --sdk `xcrun -sdk xrsimulator -show-sdk-path` -Xswiftc -target -Xswiftc x86_64-apple-xros1.0-simulator
- name: Test
run: swift test -v
41 changes: 28 additions & 13 deletions Sources/KSPlayer/Core/AppKitExtend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,6 @@ public extension NSView {
}
}

var backgroundColor: UIColor? {
get {
if let layer, let cgColor = layer.backgroundColor {
return UIColor(cgColor: cgColor)
} else {
return nil
}
}
set {
backingLayer?.backgroundColor = newValue?.cgColor
}
}

var clipsToBounds: Bool {
get {
if let layer {
Expand Down Expand Up @@ -187,6 +174,34 @@ extension NSButton {
contentTintColor = newValue
}
}

var backgroundColor: UIColor? {
get {
if let layer, let cgColor = layer.backgroundColor {
return UIColor(cgColor: cgColor)
} else {
return nil
}
}
set {
backingLayer?.backgroundColor = newValue?.cgColor
}
}
}

extension NSImageView {
var backgroundColor: UIColor? {
get {
if let layer, let cgColor = layer.backgroundColor {
return UIColor(cgColor: cgColor)
} else {
return nil
}
}
set {
backingLayer?.backgroundColor = newValue?.cgColor
}
}
}

public extension NSControl {
Expand Down
15 changes: 15 additions & 0 deletions Sources/KSPlayer/Video/SeekView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ class SeekView: UIView {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

#if canImport(AppKit)
var backgroundColor: UIColor? {
get {
if let layer, let cgColor = layer.backgroundColor {
return UIColor(cgColor: cgColor)
} else {
return nil
}
}
set {
backingLayer?.backgroundColor = newValue?.cgColor
}
}
#endif
}

extension SeekView: SeekViewProtocol {
Expand Down
14 changes: 8 additions & 6 deletions Sources/KSPlayer/Video/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ open class VideoPlayerView: PlayerView {
}
}

public let longPressGesture = UILongPressGestureRecognizer()
private var originalPlaybackRate: Float = 1.0

public let speedTipLabel: UILabel = {
Expand All @@ -113,7 +112,7 @@ open class VideoPlayerView: PlayerView {
label.font = .systemFont(ofSize: 16, weight: .medium)
label.alpha = 0
label.backgroundColor = UIColor.black.withAlphaComponent(0.5)
label.layer.cornerRadius = 4
label.backingLayer?.cornerRadius = 4
label.clipsToBounds = true
label.isHidden = true
return label
Expand Down Expand Up @@ -231,7 +230,7 @@ open class VideoPlayerView: PlayerView {
speedTipLabel.topAnchor.constraint(equalTo: safeTopAnchor, constant: 50),
speedTipLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
speedTipLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 80),
speedTipLabel.heightAnchor.constraint(equalToConstant: 30)
speedTipLabel.heightAnchor.constraint(equalToConstant: 30),
])
addConstraint()
customizeUIComponents()
Expand All @@ -251,10 +250,10 @@ open class VideoPlayerView: PlayerView {
doubleTapGesture.numberOfTapsRequired = 2
tapGesture.require(toFail: doubleTapGesture)
controllerView.addGestureRecognizer(doubleTapGesture)
#if canImport(UIKit)
longPressGesture.addTarget(self, action: #selector(longPressGestureAction(_:)))
longPressGesture.minimumPressDuration = 0.5
controllerView.addGestureRecognizer(longPressGesture)
#if canImport(UIKit)
addRemoteControllerGestures()
#endif
}
Expand Down Expand Up @@ -432,8 +431,10 @@ open class VideoPlayerView: PlayerView {
}
}

#if canImport(UIKit)
public let longPressGesture = UILongPressGestureRecognizer()
@objc open func longPressGestureAction(_ gesture: UILongPressGestureRecognizer) {
guard let playerLayer = playerLayer else { return }
guard let playerLayer else { return }

switch gesture.state {
case .began:
Expand All @@ -449,6 +450,7 @@ open class VideoPlayerView: PlayerView {
break
}
}
#endif

private func showSpeedTip(_ text: String) {
speedTipLabel.text = text
Expand All @@ -462,7 +464,7 @@ open class VideoPlayerView: PlayerView {
// 延迟后隐藏
delayItem?.cancel()
delayItem = DispatchWorkItem { [weak self] in
guard let self = self else { return }
guard let self else { return }
UIView.animate(withDuration: 0.2) {
self.speedTipLabel.alpha = 0
} completion: { _ in
Expand Down

0 comments on commit c8d1b3a

Please sign in to comment.