
Avkit
Create media playback experiences using AVKit.
Install
npx skills add dpearson2699/swift-ios-skills --skill avkit -g -a claude-code -y- Repository
- dpearson2699/swift-ios-skills1.3k
- Category
- Design
- Updated
- 3mo ago
- License
- See repository
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Create media playback experiences using AVKit. Use when adding video players with AVPlayerViewController, enabling Picture-in-Picture, routing media with AirPlay, using SwiftUI VideoPlayer views, configuring transport controls, displaying subtitles and closed captions, or integrating AVFoundation playback with system UI.
AVKit
High-level media playback UI built on AVFoundation. Provides system-standard video players, Picture-in-Picture, AirPlay routing, transport controls, and subtitle/caption display. Targets Swift 6.3 / iOS 26+.
Contents
- Setup
- AVPlayerViewController
- SwiftUI VideoPlayer
- Picture-in-Picture
- AirPlay
- Transport Controls and Playback Speed
- Subtitles and Closed Captions
- Common Mistakes
- Review Checklist
- References
Setup
Audio Session Configuration
Playback apps need an audio session category and the matching background mode when they support background audio, AirPlay, or PiP.
- Enable Background Modes > Audio, AirPlay, and Picture in Picture (the
audiovalue inUIBackgroundModes) - Set the audio session category to
.playback - Defer
setActive(true)until playback begins so you do not interrupt other audio prematurely
import AVFoundation
func configureAudioSessionForPlayback() {
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playback, mode: .moviePlayback)
} catch {
print("Audio session category failed: \(error)")
}
}
func activateAudioSessionWhenPlaybackBegins() {
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print("Audio session activation failed: \(error)")
}
}
Imports
import AVKit // AVPlayerViewController, VideoPlayer, PiP
import AVFoundation // AVPlayer, AVPlayerItem, AVAsset
AVPlayerViewController
AVPlayerViewController is the standard UIKit player. It provides system
playback controls, PiP, AirPlay, subtitles, and frame analysis out of the box.
Do not subclass it.
Basic Presentation (Full Screen)
import AVKit


