Building an immersive media viewing experience
At a glance
| Item | Summary |
|---|---|
| Purpose | Add a deeper level of immersion to media playback in your app with RealityKit and Reality Composer Pro. |
| App architecture | A Swift sample with the source-visible chain DestinationVideo → ContentView → Coordinator → EnvironmentStateHandler → SwiftUI / SwiftData APIs. |
| Main patterns | Delegate or data-source callbacks, Coordinator |
| Project style | 46 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 closure isolated to MainActor, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, @Observable, NotificationCenter. |
| Key frameworks/packages | SwiftUI, SwiftData, Foundation, AVKit, GroupActivities; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── DestinationVideo/
├── DestinationVideo.swift
├── Views/
│ ├── VideoInfoView.swift
│ ├── visionOS/
│ │ ├── ProfileButton.swift
│ │ ├── ImmersiveEnvironmentPickerView.swift
│ │ └── TrailerView.swift
│ └── VideoCardView.swift
├── Player/
│ ├── InlinePlayerView.swift
│ ├── PlayerModel.swift
│ ├── SystemPlayerView.swift
│ └── PlayerView.swift
├── Model/
│ └── visionOS/
│ └── EnvironmentStateHandler.swift
└── SharePlay/
└── WatchingCoordinator.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 6 project/configuration file(s) and 69 source declaration(s).
Overall architecture
flowchart LR
N1["DestinationVideo"]
N2["ContentView"]
N3["Coordinator"]
N4["EnvironmentStateHandler"]
N5["SwiftUI / SwiftData APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
DestinationVideo/DestinationVideo.swift:13 — architecture anchor
@main
struct DestinationVideo: App {
// ...
private let modelContainer: ModelContainer
// ...
}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 visionOS.
Ownership and state
classDiagram
DestinationVideo o-- ModelContainer : modelContainer
DestinationVideo *-- PlayerModel : player
DestinationVideo *-- ImmersiveEnvironment : immersiveEnvironment
DestinationVideo *-- ImmersiveContentBrightness : contentBrightness
Ownership evidence
DestinationVideo/DestinationVideo.swift:16 — stored dependency or nearest verified ownership anchor
@main
struct DestinationVideo: App {
// ...
private let modelContainer: ModelContainer
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
DestinationVideo |
ModelContainer (modelContainer) |
stores or receives | Initialized by the owner; the binding is immutable |
DestinationVideo |
PlayerModel (player) |
owns wrapper-managed state | Owning lexical scope |
DestinationVideo |
ImmersiveEnvironment (immersiveEnvironment) |
owns wrapper-managed state | Owning lexical scope |
DestinationVideo |
ImmersiveContentBrightness (contentBrightness) |
owns wrapper-managed state | Owning lexical scope |
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. | DestinationVideo/Model/Data/Genre.swift:38 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | DestinationVideo/Model/visionOS/ImmersiveEnvironment.swift:47 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | DestinationVideo/Player/InlinePlayerView.swift:55 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | DestinationVideo/Player/InlinePlayerView.swift:55 |
@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
DestinationVideo/Model/Data/Genre.swift:38 — representative execution boundary
extension SampleData {
@MainActor static let genres = [
Genre(id: 0, name: "Drama"),
Genre(id: 1, name: "Romance"),
Genre(id: 2, name: "Comedy"),
Genre(id: 3, name: "Action"),
Genre(id: 4, name: "Adventure"),
Genre(id: 5, name: "Documentary"),
Genre(id: 6, name: "Mystery"),
Genre(id: 7, name: "Animation"),
Genre(id: 8, name: "Sci-Fi")
]
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | DestinationVideo/ContentView.swift:12 |
| State propagation | @Observable |
Observation macro publishes source-visible changes. | DestinationVideo/Model/visionOS/ImmersiveEnvironment.swift:13 |
| State propagation | NotificationCenter |
NotificationCenter distributes named process-local events. | DestinationVideo/Player/PlayerModel.swift:153 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | DestinationVideo/ContentView.swift:8 |
| Source import | SwiftData |
The cited file imports this module; runtime use and architectural role are not inferred. | DestinationVideo/DestinationTabs.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | DestinationVideo/Extensions/DestinationVideoExtensions.swift:8 |
| Source import | AVKit |
The cited file imports this module; runtime use and architectural role are not inferred. | DestinationVideo/Player/InlinePlayerView.swift:9 |
| Source import | GroupActivities |
The cited file imports this module; runtime use and architectural role are not inferred. | DestinationVideo/Player/PlayerModel.swift:9 |
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
DestinationVideo/Views/VideoInfoView.swift:11 — representative type boundary
struct InfoView: View {
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
InfoView |
User-interface presentation and input forwarding | View |
GenreView |
User-interface presentation and input forwarding | View |
RoleView |
User-interface presentation and input forwarding | View |
InlinePlayerView |
User-interface presentation and input forwarding | View |
InlineControlsView |
User-interface presentation and input forwarding | View |
VideoContentView |
User-interface presentation and input forwarding | UIViewControllerRepresentable |
PlayerModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
PlayerViewObserver |
Observes and relays feature changes | NSObject, AVPlayerViewControllerDelegate |
SystemPlayerView |
User-interface presentation and input forwarding | Concrete collaborators/imported frameworks |
Coordinator |
Cross-object flow or session coordination | NSObject, AVPlayerViewDelegate |
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 |
|---|---|---|---|
player (DestinationVideo/ContentView.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. |
immersiveEnvironment (DestinationVideo/ContentView.swift:14) |
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. |
horizontalSizeClass (DestinationVideo/DestinationTabs.swift:17) |
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. |
videos (DestinationVideo/DestinationTabs.swift:20) |
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
DestinationVideo/ContentView.swift:12 — representative boundary
struct ContentView: View {
@Environment(PlayerModel.self) private var player
// ...
}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 |
|---|---|---|
| Cross-object flow or session coordination | Coordinator, WatchingCoordinator |
The source’s Coordinator suffix makes this role explicit. |
| Receives callback-driven events | PlaybackCoordinatorDelegate |
The source’s Delegate suffix makes this role explicit. |
| Handles callbacks or feature events | EnvironmentStateHandler |
The source’s Handler suffix makes this role explicit. |
| Feature data or observable state | PlayerModel |
The source’s Model suffix makes this role explicit. |
| Observes and relays feature changes | PlayerViewObserver |
The source’s Observer suffix makes this role explicit. |
| User-interface presentation and input forwarding | CategoryListView, CategoryView, ContentView, DetailView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | DestinationVideo/Player/PlayerModel.swift:104 |
Callback protocols invert event delivery back into the sample’s owner. |
| Coordinator | DestinationVideo/Player/SystemPlayerView.swift:25 |
A role-named coordinator centralizes cross-object flow. |
Naming conventions
- Types: Coordinator: Coordinator, WatchingCoordinator; Delegate: PlaybackCoordinatorDelegate; Handler: EnvironmentStateHandler; Model: PlayerModel; Observer: PlayerViewObserver; View: CategoryListView, CategoryView, ContentView, DetailView, GenreView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
dismissAfterDelay,makeUIViewController,updateUIViewController,makePlayerUI,willEndFullScreenPresentation,playerViewController,observePlayback,configureAudioSession. - Files:
DestinationVideo/DestinationVideo.swift,DestinationVideo/Player/InlinePlayerView.swift,DestinationVideo/Player/PlayerModel.swift,DestinationVideo/Player/SystemPlayerView.swift,DestinationVideo/Model/visionOS/EnvironmentStateHandler.swift,DestinationVideo/Player/PlayerView.swift.
Architecture takeaways
DestinationVideois the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, SwiftData, AVKit, GroupActivities 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 |
|---|---|
DestinationVideo/DestinationVideo.swift |
Cited implementation, DestinationVideo |
DestinationVideo/Views/VideoInfoView.swift |
InfoView, GenreView, RoleView, PosterCard |
DestinationVideo/ContentView.swift |
Cited implementation, SwiftUI state property wrapper, SwiftUI, ContentView |
DestinationVideo/DestinationTabs.swift |
Cited implementation, SwiftData, DestinationTabs |
DestinationVideo/Player/PlayerModel.swift |
Cited implementation, NotificationCenter, GroupActivities, Presentation, PlayerModel, PlayerViewObserver |
DestinationVideo/Player/SystemPlayerView.swift |
Coordinator, SystemPlayerView |
DestinationVideo/Model/Data/Genre.swift |
@MainActor, Genre |
DestinationVideo/Model/visionOS/ImmersiveEnvironment.swift |
async declaration or closure, @Observable, ImmersiveEnvironment, ImmersiveSpaceState |
DestinationVideo/Player/InlinePlayerView.swift |
Task closure isolated to MainActor, Task, AVKit, InlinePlayerView, InlineControlsView, VideoContentView |
DestinationVideo/Extensions/DestinationVideoExtensions.swift |
Foundation, Feature implementation |
DestinationVideo/Views/visionOS/ProfileButton.swift |
ProfileButtonView, ProfileIconView, ProfileDetailView, ExpandingProfileButtonStyle, ExpandEffect, FadeEffect |
DestinationVideo/Model/visionOS/EnvironmentStateHandler.swift |
EnvironmentStateType, EnvironmentStateHandler |
DestinationVideo/Player/PlayerView.swift |
PlayerControlsStyle, PlayerView |
DestinationVideo/SharePlay/WatchingCoordinator.swift |
WatchingCoordinator, PlaybackCoordinatorDelegate |
DestinationVideo/Views/VideoCardView.swift |
VideoCardStyle, VideoCardView |
DestinationVideo/Views/visionOS/ImmersiveEnvironmentPickerView.swift |
ImmersiveEnvironmentPickerView, StudioButton |