-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathQuickPoseSimulatedCameraView.swift
50 lines (43 loc) · 1.44 KB
/
QuickPoseSimulatedCameraView.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
//
// QuickPoseSimulatedCameraView.swift
//
//
// Created by QuickPose.ai on 12/01/2023.
//
import Foundation
import SwiftUI
import AVFoundation
#if QUICKPOSECORE
#else
import QuickPoseCore
import QuickPoseCamera
#endif
public struct QuickPoseSimulatedCameraView: View {
let delegate: QuickPoseCaptureAVAssetOutputSampleBufferDelegate?
let videoGravity: AVLayerVideoGravity
@State var cameraReady: Bool = false
@State var camera: QuickPoseSimulatedCamera? = nil
public init(useFrontCamera: Bool, delegate: QuickPoseCaptureAVAssetOutputSampleBufferDelegate?, video: URL, onVideoLoop: (()->())? = nil, videoGravity: AVLayerVideoGravity = .resizeAspectFill) {
self.camera = QuickPoseSimulatedCamera(useFrontCamera: useFrontCamera, asset: AVAsset(url: video), onVideoLoop: onVideoLoop)
self.delegate = delegate
self.videoGravity = videoGravity
}
public var body: some View {
ZStack(alignment: .top) {
if cameraReady, let avAssetPlayer = camera?.player {
QuickPoseAssetRenderView(player: avAssetPlayer, videoGravity: videoGravity)
} else {
EmptyView()
}
}.onAppear {
do {
try camera?.start(delegate: delegate)
cameraReady = true
} catch let error {
print(error)
}
}.onDisappear(){
camera?.stop()
}
}
}