Creating a multiview video playback experience in visionOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Build an interface that plays multiple videos simultaneously and handles transitions to different experience types gracefully. |
| App architecture | A Swift sample with the source-visible chain MultiviewVideoPlaybackApp → ContentView → MultiviewStateModel → ItemVideoPlayer → AVKit APIs. |
| Main patterns | Delegate or data-source callbacks, Binding-based state propagation |
| Project style | 13 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, async declaration or closure, Task, Task closure isolated to MainActor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, ObservableObject, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, AVKit, UIKit, AVFoundation, Foundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── MultiviewVideoPlayback/
├── MultiviewVideoPlaybackApp.swift
├── Helpers/
│ └── SceneDelegate.swift
├── Models/
│ ├── MultiviewStateModel.swift
│ ├── VideoModel.swift
│ └── Video.swift
└── Views/
├── VideoItemSelectionView.swift
├── ContentView.swift
├── ItemVideoPlayer.swift
├── MultiviewVideoSelectionView.swift
├── SystemVideoPlayer.swift
├── ThumbnailView.swift
└── VideoHomeView.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 14 source declaration(s).
Overall architecture
flowchart LR
N1["MultiviewVideoPlaybackApp"]
N2["ContentView"]
N3["MultiviewStateModel"]
N4["ItemVideoPlayer"]
N5["AVKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
MultiviewVideoPlayback/MultiviewVideoPlaybackApp.swift:10 — architecture anchor
@main
struct MultiviewVideoPlaybackApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: CustomApplicationDelegate
var body: some Scene {
WindowGroup {
ContentView()
.frame(minWidth: 1200, minHeight: 600)
}
.windowResizability(.contentSize)
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into AVKit.
Ownership and state
classDiagram
MultiviewVideoPlaybackApp o-- CustomApplicationDelegate : appDelegate
CustomSceneDelegate o-- UIScene : scene
MultiviewStateModel *-- Array : videoModels
MultiviewStateModel o-- VideoModel : embeddedVideo
Ownership evidence
MultiviewVideoPlayback/MultiviewVideoPlaybackApp.swift:12 — stored dependency or nearest verified ownership anchor
@main
struct MultiviewVideoPlaybackApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: CustomApplicationDelegate
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
MultiviewVideoPlaybackApp |
CustomApplicationDelegate (appDelegate) |
stores or receives | Owning lexical scope |
CustomSceneDelegate |
UIScene (scene) |
stores or receives | App/module collaborators |
MultiviewStateModel |
Array (videoModels) |
owns value state | App/module collaborators |
MultiviewStateModel |
VideoModel (embeddedVideo) |
stores or receives | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | MultiviewVideoPlayback/Models/MultiviewStateModel.swift:11 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | MultiviewVideoPlayback/Models/MultiviewStateModel.swift:47 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | MultiviewVideoPlayback/Models/MultiviewStateModel.swift:112 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | MultiviewVideoPlayback/Models/Video.swift:22 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
MultiviewVideoPlayback/Models/MultiviewStateModel.swift:11 — representative execution boundary
@Observable @MainActor
final class MultiviewStateModel: AVExperienceController.Delegate {
// ...
var videoModels: [VideoModel] = []
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | @Observable |
Observation macro publishes source-visible changes. | MultiviewVideoPlayback/Helpers/SceneDelegate.swift:10 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | MultiviewVideoPlayback/Helpers/SceneDelegate.swift:27 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | MultiviewVideoPlayback/Views/ContentView.swift:11 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiviewVideoPlayback/Helpers/AVMultiviewManager+Extension.swift:9 |
| Source import | AVKit |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiviewVideoPlayback/Helpers/AVMultiviewManager+Extension.swift:8 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiviewVideoPlayback/Helpers/SceneDelegate.swift:8 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiviewVideoPlayback/Models/Video.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | MultiviewVideoPlayback/Models/Video.swift:10 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
MultiviewVideoPlayback/MultiviewVideoPlaybackApp.swift:11 — representative type boundary
@main
struct MultiviewVideoPlaybackApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: CustomApplicationDelegate
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
MultiviewVideoPlaybackApp |
Application entry and top-level composition | App |
CustomSceneDelegate |
Receives callback-driven events | NSObject, UIWindowSceneDelegate |
CustomApplicationDelegate |
Receives callback-driven events | NSObject, UIApplicationDelegate, ObservableObject |
MultiviewStateModel |
Feature data or observable state | AVExperienceController.Delegate |
VideoModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
VideoItemSelectionView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
ItemVideoPlayer |
Owns media or timeline playback | UIViewControllerRepresentable |
MultiviewVideoSelectionView |
User-interface presentation and input forwarding | View |
SystemVideoPlayer |
Owns media or timeline playback | UIViewControllerRepresentable |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
metadataItem (MultiviewVideoPlayback/Models/Video.swift:35) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
player (MultiviewVideoPlayback/Models/VideoModel.swift:13) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
appDelegate (MultiviewVideoPlayback/MultiviewVideoPlaybackApp.swift:12) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
height (MultiviewVideoPlayback/Views/VideoItemSelectionView.swift:38) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
MultiviewVideoPlayback/Models/Video.swift:35 — representative boundary
fileprivate static func metadataItem(key identifier: AVMetadataIdentifier, value: Any) -> AVMetadataItem {
let item = AVMutableMetadataItem()
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | MultiviewVideoPlaybackApp |
The source’s App suffix makes this role explicit. |
| Receives callback-driven events | CustomApplicationDelegate, CustomSceneDelegate |
The source’s Delegate suffix makes this role explicit. |
| Feature data or observable state | MultiviewStateModel, VideoModel |
The source’s Model suffix makes this role explicit. |
| Owns media or timeline playback | ItemVideoPlayer, SystemVideoPlayer |
The source’s Player suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, MultiviewVideoSelectionView, ThumbnailView, VideoHomeView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | MultiviewVideoPlayback/Helpers/SceneDelegate.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
| Binding-based state propagation | MultiviewVideoPlayback/Views/VideoHomeView.swift:12 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Main application flow
sequenceDiagram
actor User
participant View as Selection view
participant State as State model
participant Exp as Experience controller
User->>View: Add/remove video
View->>State: videoSelected(item, inMultiview)
State->>Exp: grouped transition
Exp-->>State: transition context delegate callback
State->>State: update isAddedToMultiview/embeddedVideo
State-->>View: observable state rerenders
Reference code
MultiviewVideoPlayback/Views/MultiviewVideoSelectionView.swift:24 — source excerpt
ForEach(multiviewStateModel.videoModels, id: \.video) { videoModel in
Button {
Task {
await multiviewStateModel.videoSelected(
videoModel: videoModel,
inMultiview: fromMultiviewContentSelection
)
}
} label: {
VideoItemSelectionView(
videoModel: videoModel,
inMultiviewContentSelection: fromMultiviewContentSelection
)
.padding(.vertical, 5)
}
.buttonBorderShape(.roundedRectangle(radius: 25.0))
}Naming conventions
- Types: App: MultiviewVideoPlaybackApp; Delegate: CustomApplicationDelegate, CustomSceneDelegate; Model: MultiviewStateModel, VideoModel; Player: ItemVideoPlayer, SystemVideoPlayer; View: ContentView, MultiviewVideoSelectionView, ThumbnailView, VideoHomeView, VideoItemSelectionView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
sceneWillEnterForeground,sceneDidBecomeActive,sceneDidDisconnect,application,populate,videoSelected,experienceController,setFallbackScene. - Files:
MultiviewVideoPlayback/MultiviewVideoPlaybackApp.swift,MultiviewVideoPlayback/Models/MultiviewStateModel.swift,MultiviewVideoPlayback/Models/VideoModel.swift,MultiviewVideoPlayback/Views/VideoItemSelectionView.swift,MultiviewVideoPlayback/Views/ContentView.swift,MultiviewVideoPlayback/Views/ItemVideoPlayer.swift.
Architecture takeaways
MultiviewVideoPlaybackAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, AVKit, UIKit, AVFoundation through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
MultiviewVideoPlayback/MultiviewVideoPlaybackApp.swift |
Cited implementation, MultiviewVideoPlaybackApp |
MultiviewVideoPlayback/Models/Video.swift |
Cited implementation, Task closure isolated to MainActor, AVFoundation, Foundation, Video |
MultiviewVideoPlayback/Models/VideoModel.swift |
Cited implementation, VideoModel |
MultiviewVideoPlayback/Views/VideoItemSelectionView.swift |
Cited implementation, VideoItemSelectionView, ContentSelectionViewItem |
MultiviewVideoPlayback/Helpers/SceneDelegate.swift |
Cited implementation, @Observable, ObservableObject, UIKit, CustomSceneDelegate, CustomApplicationDelegate |
MultiviewVideoPlayback/Views/VideoHomeView.swift |
Cited implementation, VideoHomeView |
MultiviewVideoPlayback/Models/MultiviewStateModel.swift |
@MainActor, async declaration or closure, Task, MultiviewStateModel |
MultiviewVideoPlayback/Views/ContentView.swift |
SwiftUI state property wrapper, ContentView |
MultiviewVideoPlayback/Helpers/AVMultiviewManager+Extension.swift |
SwiftUI, AVKit, Feature implementation |
MultiviewVideoPlayback/Views/ItemVideoPlayer.swift |
ItemVideoPlayer |
MultiviewVideoPlayback/Views/MultiviewVideoSelectionView.swift |
MultiviewVideoSelectionView |
MultiviewVideoPlayback/Views/SystemVideoPlayer.swift |
SystemVideoPlayer |
MultiviewVideoPlayback/Views/ThumbnailView.swift |
ThumbnailView |