Documentation Index
Fetch the complete documentation index at: https://docs.prism.byescaleira.com/llms.txt
Use this file to discover all available pages before exploring further.
PrismVideo wraps AVFoundation’s export pipeline in a Swift concurrency-friendly API. You create a downloader with a remote URL, call download(), and receive an AsyncStream of status updates—progress fractions, a completion path, or a typed error—without any delegate wiring or callback pyramids.
Installation
Downloading a video
The following example downloads a remote video and writes it to a temporary file at highest quality.PrismVideoDownloader is an actor, so download() is isolated to its executor. The AsyncStream delivers updates on the main run loop because Timer.publish is used for progress polling.
The exported file lands in
FileManager.default.temporaryDirectory. If you need to keep it beyond the current session, move it to the Documents directory after the .completed case.PrismVideoDownloaderStatus
Each value emitted by the stream is one of three cases:| Case | Payload | Meaning |
|---|---|---|
.downloading(progress:session:) | Double (0.0–1.0), AVAssetExportSession | Export is in progress |
.completed(path:) | URL | Export finished; file is at this path |
.error(_:) | PrismVideoError | Export failed with a typed error |
session in .downloading gives you access to AVAssetExportSession for cancellation. It is marked @unchecked Sendable because AVAssetExportSession does not conform to Sendable—do not share it across isolation domains.
PrismVideoError
PrismVideoError conforms to PrismError, which means it includes a localized description, a failure reason, and a recovery suggestion.
| Case | Description | Recovery |
|---|---|---|
.assetNotPlayable | The AVAsset could not be prepared for playback | Verify the source URL and try reloading |
.missingTracks | The file has no valid video or audio tracks | Confirm the media file is not corrupted |
.failedToCreateExportSession | AVAssetExportSession could not be initialized | Try different export parameters |
.custom(message:) | Wraps an underlying system error message | Inspect the message for details |
PrismVideoEntity
UsePrismVideoEntity to model video metadata throughout your app. All fields except id, url, and title are optional.
PrismVideoEntity is Identifiable, Equatable, Hashable, and Sendable, so you can store it in PrismStore state or pass it across actor boundaries without any extra work.
PrismVideoResolution
PrismVideoResolution maps pixel heights to named quality tiers. Initialize it from a raw pixel height and it selects the correct case automatically.
| Case | Pixel height range | Label |
|---|---|---|
.SD | 0 – 719 | "SD" |
.HD | 720 – 1079 | "720p HD" |
.fullHD | 1080 – 2159 | "1080p HD" |
._4K | 2160+ | "4K" |
Complete download-and-store example
The following pattern downloads a video, updates aPrismStore counter with progress, and stores the local path on completion.