-
Notifications
You must be signed in to change notification settings - Fork 7
/
VideoDetail.swift
102 lines (83 loc) · 4.44 KB
/
VideoDetail.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// VideoDetail.swift
// VideoNavigation-Example
//
// Created by shayanbo on 2023/7/21.
//
import SwiftUI
import AVKit
import VideoPlayerContainer
struct VideoDetail: View {
let video: Video
let player: AVPlayer
@StateObject private var context = Context()
@Environment(\.dismiss) private var dismiss
var body: some View {
GeometryReader { proxy in
VStack {
PlayerWidget(context)
.background(.black)
.frame(height: proxy.size.width / video.aspectRatio)
.onAppear {
context.control.configure(.halfScreen(.top), shadow: nil)
context.control.configure(.halfScreen(.bottom), shadow: nil)
context.control.configure(shadow: AnyView(
Rectangle().fill(.black.opacity(0.2)).allowsHitTesting(false)
))
context.control.configure(.halfScreen(.top), transition: .opacity)
context.control.configure(.halfScreen(.bottom), transition: .opacity)
context.control.configure(.halfScreen, insets: .init(top: 0, leading: 10, bottom: 0, trailing: 10))
context.control.configure(.halfScreen(.top1)) {[
BackWidget(),
Spacer(),
Image(systemName: "switch.2").frame(width: 25, height: 35).foregroundColor(.white),
Image(systemName: "airplayvideo").frame(width: 25, height: 35).foregroundColor(.white),
Spacer().frame(width: 50),
Image(systemName: "gearshape").frame(width: 25, height: 35).foregroundColor(.white),
]}
context.control.configure(.halfScreen(.bottom1)) {[
Rectangle().fill(.white).frame(height:5).cornerRadius(2).padding(.horizontal, -20)
]}
context.control.configure(.halfScreen(.bottom2)) {[
Text("00:00").foregroundColor(.white),
Spacer(),
Image(systemName: "square.on.square").frame(width: 25, height: 25).foregroundColor(.white),
]}
context.control.configure(.halfScreen(.center)) { views in
HStack(spacing: 30) {
ForEach(views) { $0 }
}
}
context.control.configure(.halfScreen(.center)) {[
Image(systemName: "backward.end.circle")
.resizable()
.scaledToFit()
.foregroundColor(.white)
.frame(width: 30, height: 30),
Image(systemName: "play.fill")
.resizable()
.scaledToFit()
.foregroundColor(.white)
.frame(width: 50, height: 50),
Image(systemName: "forward.end.circle")
.resizable()
.scaledToFit()
.foregroundColor(.white)
.frame(width: 30, height: 30),
]}
context.control.configure(displayStyle: .manual(firstAppear: false, animation: .default))
context.render.attach(player: player)
if player.currentItem == nil {
let item = AVPlayerItem(url: Bundle.main.url(forResource: "demo", withExtension: "mp4")!)
player.replaceCurrentItem(with: item)
player.play()
} else if player.rate == 0 {
player.play()
}
}
Spacer()
}
}
.navigationBarHidden(true)
}
}