feat: 视频全屏展示
This commit is contained in:
parent
9b76b341f2
commit
c6eb0639d1
@ -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 {
|
||||
@State private var showLottieAnimation = true // 控制Lottie动画显示
|
||||
@State private var showScalingOverlay = false
|
||||
@ -152,8 +169,7 @@ struct BlindBoxView: View {
|
||||
// Video Player
|
||||
if let player = videoPlayer {
|
||||
ZStack(alignment: .topLeading) {
|
||||
VideoPlayer(player: player)
|
||||
.aspectRatio(contentMode: .fill)
|
||||
AVPlayerController(player: $videoPlayer)
|
||||
.frame(
|
||||
width: isPortraitVideo ?
|
||||
UIScreen.main.bounds.height * scale * 1/aspectRatio :
|
||||
@ -162,22 +178,12 @@ struct BlindBoxView: View {
|
||||
UIScreen.main.bounds.height * scale :
|
||||
UIScreen.main.bounds.width * scale * 1/aspectRatio
|
||||
)
|
||||
.clipped()
|
||||
.opacity(scale == 1 ? 1 : 0.7)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
withAnimation(.easeInOut(duration: 0.1)) {
|
||||
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
|
||||
if showControls {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user