feat: 视频全屏展示

This commit is contained in:
jinyaqiu 2025-08-27 18:23:35 +08:00
parent 9b76b341f2
commit c6eb0639d1

View File

@ -38,6 +38,23 @@ struct VisualEffectView: UIViewRepresentable {
} }
} }
struct AVPlayerController: UIViewControllerRepresentable {
@Binding var player: AVPlayer?
func makeUIViewController(context: Context) -> AVPlayerViewController {
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = true
controller.entersFullScreenWhenPlaybackBegins = true
controller.exitsFullScreenWhenPlaybackEnds = true
return controller
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
uiViewController.player = player
}
}
struct BlindBoxView: View { struct BlindBoxView: View {
@State private var showLottieAnimation = true // Lottie @State private var showLottieAnimation = true // Lottie
@State private var showScalingOverlay = false @State private var showScalingOverlay = false
@ -152,8 +169,7 @@ struct BlindBoxView: View {
// Video Player // Video Player
if let player = videoPlayer { if let player = videoPlayer {
ZStack(alignment: .topLeading) { ZStack(alignment: .topLeading) {
VideoPlayer(player: player) AVPlayerController(player: $videoPlayer)
.aspectRatio(contentMode: .fill)
.frame( .frame(
width: isPortraitVideo ? width: isPortraitVideo ?
UIScreen.main.bounds.height * scale * 1/aspectRatio : UIScreen.main.bounds.height * scale * 1/aspectRatio :
@ -162,22 +178,12 @@ struct BlindBoxView: View {
UIScreen.main.bounds.height * scale : UIScreen.main.bounds.height * scale :
UIScreen.main.bounds.width * scale * 1/aspectRatio UIScreen.main.bounds.width * scale * 1/aspectRatio
) )
.clipped()
.opacity(scale == 1 ? 1 : 0.7) .opacity(scale == 1 ? 1 : 0.7)
.contentShape(Rectangle())
.onTapGesture { .onTapGesture {
withAnimation(.easeInOut(duration: 0.1)) { withAnimation(.easeInOut(duration: 0.1)) {
showControls.toggle() showControls.toggle()
} }
} }
.onAppear {
player.seek(to: .zero)
player.play()
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { _ in
player.seek(to: .zero)
player.play()
}
}
// Back Button - Always on top // Back Button - Always on top
if showControls { if showControls {