This project demonstrates how to play video content in iOS using AVPlayer and AVPlayerViewController.
It supports both clear (unencrypted) and encrypted (FairPlay DRM-protected) content.
The project also showcases how to integrate FairPlay Streaming (FPS) license acquisition and use modern async/await patterns in Swift for handling network calls and DRM workflows.
- Playback using
AVPlayerandAVPlayerViewController - Supports both clear and encrypted content playback
- Integration with FairPlay DRM (certificate, SPC, CKC flow)
AVContentKeySessionfor handling content key requests- Async/await networking with
URLSession - XML parsing for certificate/CKC extraction
- Error handling with a dedicated
PlaybackErrorenum - SwiftUI integration with
UIViewControllerRepresentable
- Player.swift → Handles AVPlayer setup, content key session, DRM flow
- Parser.swift → Parses XML responses (
<cert>and<ckc>tags) and decodes base64 data - PlayerViewController.swift → A
UIViewControllerRepresentablewrapper to use AVPlayer in SwiftUI - PlaybackError.swift → Centralized error definitions for playback and DRM handling
- SourceConfig.swift → Configuration for source URL, license server, and headers
- AVPlayer requests a key for encrypted content
AVContentKeySessionDelegateprovides the request- App fetches certificate from the server
- SPC is generated and sent to the license server
- License server returns CKC
- CKC is processed and provided back to AVPlayer
- Encrypted content starts playback
- iOS 15+
- Xcode 14+
- Swift 5.7+
- Configure your certificate URL and license server URL in
SourceConfig - Run the app
- The player will automatically handle clear playback or perform the DRM flow for encrypted playback
- Supports both raw CKC and XML-wrapped CKC formats
- Handles both clear and encrypted content seamlessly
- Demonstrates error handling when URLs or responses are invalid
- Designed for educational/demo purposes – adapt for production use
- avplayer, ios, swift, swiftUI, sample-app