MiniPlayer/Sources/ProgressSlider.swift
yumoqing 6811572b7e fix: rewrite UI as pure SwiftUI, fix crash/fullscreen/height issues
- Skip BricksView, render video directly in SwiftUI (fixes 1/3 height)
- Fullscreen uses plain NSView+AVPlayerLayer (fixes objc_release crash)
- Remove NSApp.hide(nil) (fixes fullscreen not showing)
- Add volume +/- buttons and volume slider indicator
- Add iOS/iPadOS support with #if os guards
- ProgressSlider decoupled from BricksEngine
- PlayerBridge no longer depends on player.ui JSON
2026-06-22 00:04:06 +08:00

47 lines
1.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
import AVFoundation
/// ProgressSlider SwiftUIseek
struct ProgressSlider: View {
let player: AVPlayer
@ObservedObject var bridge: PlayerBridge
@State private var isDragging = false
var body: some View {
GeometryReader { geo in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 2)
.fill(Color.secondary.opacity(0.3))
.frame(height: 4)
RoundedRectangle(cornerRadius: 2)
.fill(Color.accentColor)
.frame(width: geo.size.width * bridge.progressRatio, height: 4)
Circle()
.fill(Color.accentColor)
.frame(width: 14, height: 14)
.offset(x: geo.size.width * bridge.progressRatio - 7)
.shadow(radius: 2)
}
.frame(height: 20)
.contentShape(Rectangle())
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { value in
isDragging = true
let ratio = max(0, min(1, value.location.x / geo.size.width))
if bridge.cachedDuration > 0 {
let seekTime = ratio * bridge.cachedDuration
player.seek(to: CMTime(seconds: seekTime, preferredTimescale: 600))
}
}
.onEnded { _ in
isDragging = false
}
)
}
.frame(height: 20)
}
}