-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainView.swift
63 lines (56 loc) · 2.12 KB
/
MainView.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
//
// ContentView.swift
// watermark
//
// Created by Faisal Memon on 09/02/2023.
//
import SwiftUI
import AVKit
struct MainView: View {
@State var duration: TimeInterval = 0.0
@State var progress = 0.0
@State var showProgressScreen = false
var body: some View {
NavigationStack {
VStack {
Text("Original Video")
if duration != 0 {
VideoPlayer(player: AVPlayer(url: Bundle.main.url(forResource: "donut-spinning", withExtension: "mp4")!))
.frame(height: 70)
} else {
VideoPlayer(player: AVPlayer(url: Bundle.main.url(forResource: "donut-spinning", withExtension: "mp4")!))
.frame(height: 400)
Text("Watermark")
Image(systemName: "seal")
.frame(height: 20)
}
if duration != 0 {
Text("Watermarked Video")
Text("Created after \(duration) seconds")
VideoPlayer(player: AVPlayer(url: try! Resource().outputURL))
.frame(height: 400)
} else {
Button("Add Watermark") {
let helper = WatermarkHelper()
Task {
if let exporter = try? await helper.exporterForWatermarkedVideo(progress: $progress) {
showProgressScreen = true
_ = try? await exporter.export()
duration = exporter.duration ?? 0.0
showProgressScreen = false
}
}
}.navigationDestination(isPresented: $showProgressScreen) {
ProgressVideoView(bindingProgress: $progress)
}
}
}
.padding()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}