As iOS lead on a dance-class app, which media features would you build directly on AVPlayer and AVCaptureSession, and which leave to AVPlayerViewController and the system camera?
answer
- what the system UI gives for free
- future releases restyle it for you
- an overlay slot instead of a subclass
- cost of a custom player's controls
- a session only for custom capture
basics
~20 sDefault to AVPlayerViewController, which brings PiP, AirPlay, Now Playing and each release's controls; drop to AVPlayer with AVPlayerLayer only for playback UI it cannot host. Build on AVCaptureSession only when recording needs custom framing, controls or frames.
solid answer
~40 sMy default is the system: `AVPlayerViewController` for watching lessons, because it brings Picture in Picture, AirPlay, Now Playing updates (`updatesNowPlayingInfoCenter` defaults to `true`), speed and subtitle menus, accessibility, and Apple's restyling every release. Its `contentOverlayView` covers most branding without subclassing, which Apple does not support. A custom player, `AVPlayer` plus `AVPlayerLayer`, earns its place only for interaction the controller cannot host, say a mirror-mode toggle or a per-count scrubber; then the team owns controls, time observers, item status, `AVPictureInPictureController` and Now Playing. For capture, the system camera picker returns a movie with little code; an `AVCaptureSession` is justified when the recorder needs live overlays, custom controls or frame analysis. I write the rule down and revisit it when a feature truly needs more.
go deeper
Recall what AVPlayerViewController provides out of the box and that it is not subclassed.
Explain the extra work a custom AVPlayerLayer player takes on: controls, time observers, item status and PiP.
Weigh a concrete feature request against the system player's overlay and options before agreeing to a custom build.
Set the team default and the written bar for leaving it, and plan parity and per-release upkeep for every custom media surface.
## The decision a lead owns AVFoundation lets an app build everything itself: its own player screen, its own camera, its own export pipeline. AVKit and UIKit offer system components that do much of the same with far less code. The lead's job is to set the default and the bar for leaving it, because every custom piece becomes a feature the team maintains across iOS releases. There is no single right answer; the trade-off depends on how central each media feature is to the product and how distinctive it must look. ## What the system player gives you `AVPlayerViewController` is AVKit's full player. Apple says it matches the native players and **adopts new features and styling of future releases automatically**. Out of the box it brings: - Transport controls, scrubbing and skipping. - **Picture in Picture**, with `allowsPictureInPicturePlayback` defaulting to `true`. - **AirPlay**, given the right background mode. - **Now Playing** integration, since `updatesNowPlayingInfoCenter` defaults to `true`. - Playback speeds (`speeds`, `selectSpeed(_:)`) and subtitle selection. - The system's accessibility for every control. Customisation is bounded: Apple does not support subclassing, `contentOverlayView` places your views between the video and the controls, and `showsPlaybackControls = false` hands the controls over to you entirely. ## What a custom player costs Building on `AVPlayer` with an `AVPlayerLayer` gives full control of the screen, and a list of jobs the system player did for you: 1. Every control, its layout, states and accessibility labels. 2. Time display through `addPeriodicTimeObserver(forInterval:queue:using:)`, whose token must be retained and paired with `removeTimeObserver(_:)`; the header calls releasing it without removal undefined behaviour. 3. Readiness and failure through key-value observing of `AVPlayerItem.status`, recreating a failed item. 4. Picture in Picture through `AVPictureInPictureController`, built from a `ContentSource(playerLayer:)` and gated by `isPictureInPictureSupported()`. 5. Now Playing and remote commands through the MediaPlayer framework. 6. Re-checking all of it each iOS release, because nothing updates by itself. That cost is worth paying when the interaction is the product: a mirror toggle for practising, a loop over counts five to eight, a slow-motion control tied to the choreography. It is not worth paying for a brand colour on the scrubber. Before approving a custom player, a lead can ask a short list of questions: - Can `contentOverlayView`, the speed menu or `requiresLinearPlayback` deliver the request inside the system player? - Which system features would the custom screen have to rebuild, and who owns that parity? - Will the feature still differ from the system player after the next iOS release restyles it? - Is the custom screen the main lesson experience, or a corner the product could live without? ## Capture: picker or session The same reasoning applies to recording. UIKit's system camera picker records a movie with almost no code and returns a file, with the system's own controls. An `AVCaptureSession` with an `AVCaptureMovieFileOutput` is justified when the recorder needs what the picker cannot give: | Need | System camera picker | `AVCaptureSession` | |---|---|---| | Record a clip and get a file | yes | yes | | Live overlay on the preview (mirror guide, count markers) | limited | yes, through `AVCaptureVideoPreviewLayer` | | Custom record button, timer, auto-stop | limited | yes, with `maxRecordedDuration` | | Frame analysis during capture | no | yes, with `AVCaptureVideoDataOutput` | A custom session also brings its obligations: authorization flows, a serial session queue because `startRunning()` blocks, interruption notifications and device-specific presets. ## Editing and export For joining and trimming clips, `AVMutableComposition` plus an `AVAssetExportSession` preset covers most products. An `AVAssetWriter` pipeline, sample by sample with your own encoder settings, is the custom end of the same scale, and it needs the same justification. Feed-level concerns such as player pools and preloading are a separate design question, covered with mobile video playback design. ## Rules worth writing down - The system player and system camera are the default; a custom one needs a named feature that requires it. - A custom player ships with PiP, Now Playing and accessibility parity, or does not ship. - All capture-session calls go through one serial queue. - Every time observer and notification token has an owner and a removal point. - Revisit the choice when a release adds system features, since the gap may close.
- The designers want a branded badge on the lesson video; does that force a custom player?No. `AVPlayerViewController`'s `contentOverlayView` hosts views between the video and the system controls, which covers badges, watermarks and count markers. Subclassing is not supported, and hiding the controls with `showsPlaybackControls = false` moves every control onto the team, so the overlay is the first answer.
- If you do build a custom player, what must reach parity before it ships?Picture in Picture through `AVPictureInPictureController`, Now Playing and remote commands, accessible controls, failure handling from `AVPlayerItem.status`, and time observers retained and removed with `removeTimeObserver(_:)`. Without those, users lose features the system player had for free.
- A custom player is needed to put any branding on the video
- Subclassing AVPlayerViewController is the supported way to customise it
- A custom AVPlayerLayer screen gets Picture in Picture automatically
- Recording any video at all requires building an AVCaptureSession
- Once built, a custom player needs no rework on new iOS releases