Learn how to get the recorded videos from the Result<CameraResult, CameraError>
type in the Camera
’s onDismiss
closure.
Success
A Recording
has a duration
and contains an array of Video
s. The array contains either one Video
(for single camera recordings or a video that was reacted to) or two Video
s (for dual camera recordings.)
Each Video
has:
public struct Video: Equatable, Sendable { /// The URL of the recorded video file. public let url: URL /// The position and size of the video. public let rect: CGRect }
- A
url
to the video file that is stored in a temporary location. Make sure to copy the file to a permanent location if you want to access it later. - A
rect
that contains the position of each video as it was shown in the camera preview. For dual camera recordings, you can use theseCGRect
s to arrange the videos as they were laid out in the camera.
Standard and Dual Camera
If the user has recorded videos, the .recording
case will contain an array of Recording
s, each representing a segment of the recorded video.
case let .success(.recording(recordings)): for recording in recordings { print(recording.duration) for video in recording.videos { print(video.url) print(video.rect) } }
Video Reaction
If the user has recorded a reaction, the .reaction
case will contain the video that was reacted to and an array of Recording
s, each representing a segment of the recorded video.
case let .success(.reaction(video, reactionRecordings)): print(video.duration) for recording in reactionRecordings { print(recording.duration) for video in recording.videos { print(video.url) print(video.rect) } }
Failure
The .failure
case has an associated value of CameraError
, which is either .cancelled
if the user has cancelled the camera without recording anything, or .permissionsMissing
if the user has not allowed accessing their camera and/or microphone.
case let .failure(error): print(error.localizedDescription) isPresented = false
Full Code
Here’s the full code:
import IMGLYCameraimport SwiftUI
struct RecordingsCameraSolution: View { let settings = EngineSettings(license: secrets.licenseKey, userID: "<your unique user id>")
@State private var isPresented = false
var body: some View { Button("Use the Camera") { isPresented = true } .fullScreenCover(isPresented: $isPresented) { Camera(settings) { result in switch result { case let .success(.recording(recordings)): for recording in recordings { print(recording.duration) for video in recording.videos { print(video.url) print(video.rect) } }
case let .success(.reaction(video, reactionRecordings)): print(video.duration) for recording in reactionRecordings { print(recording.duration) for video in recording.videos { print(video.url) print(video.rect) } }
case let .failure(error): print(error.localizedDescription) isPresented = false } } } }}