This repository provides a SwiftUI sample application with complete source code, demonstrating how to integrate the FastPix iOS Player SDK into a SwiftUI-based iOS app.
It showcases how the FastPix Player can be embedded within SwiftUI using AVPlayerViewController under the hood, enabling a fully customizable video playback experience.
- Seamless video playback
- Subtitle and audio track switching
- Playlist management
The FastPix SDK simplifies video playback while giving developers full control over UI, behavior, and user experience.
Before running the demo, make sure you have:
- Xcode preinstalled in your system.
This project already includes the FastPix iOS Player SDK integrated via Swift Package Manager (SPM).
To get started:
- Clone the repository:
git clone "https://github.com/FastPix/fastpix-ios-player-swiftui-demo.git"- Open the project in Xcode:
cd fastpix-ios-player-swiftui-demo-
open PlayerSwiftUI.xcodeproj
-
Build and run the app on a simulator or real device
import FastPixPlayerSDK
//Create Playlist
let playlist: [FastPixPlaylistItem] = [
FastPixPlaylistItem(
playbackId: "PLAYBACK_ID",
title: "Sample Video",
duration: "00:00:00",
token: "",
drmToken: ""
)
]playerViewController.addPlaylist(playlist)
playerViewController.isAutoPlayEnabled = true
playerViewController.isLoopEnabled = true
//Setup Delegates
playerViewController.subtitleTrackDelegate = coordinatorWrap the UIKit player using UIViewControllerRepresentable.
struct FastPixPlayerRepresentable: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> FastPixPlayerHostVC {
return FastPixPlayerHostVC()
}
func updateUIViewController(_ uiViewController: FastPixPlayerHostVC, context: Context) {}
}Delegate Handling
func onSubtitleCueChange(information: SubtitleRenderInfo) {
DispatchQueue.main.async {
if information.text.isEmpty {
self.viewModel.subtitleText = ""
self.viewModel.showSubtitle = false
} else {
self.viewModel.subtitleText = information.text
self.viewModel.showSubtitle = true
}
}
}SwiftUI Rendering
if viewModel.showSubtitle {
Text(viewModel.subtitleText)
.foregroundColor(.white)
.font(.system(size: 16, weight: .medium))
.padding(.horizontal, 16)
.padding(.vertical, 6)
.background(Color.black.opacity(0.5))
.cornerRadius(6)
}Handles:
- UI rendering
- State management
- Subtitle overlay
- Navigation
- Hosting AVPlayerViewController
- Delegate communication
Handles:
- Playback engine
- Audio & subtitle parsing
- Skip segments
- Buffering & playback states
- Seek preview thumbnails
SDK Handles
- Video playback
- Audio track switching
- Subtitle parsing
- Skip segment logic
- Playback speed
- Buffering state
- Thumbnail previews
App Layer Handles
- UI controls (buttons, sliders)
- Subtitle rendering UI
- Playlist UI
- Settings UI (audio/subtitles)
- Custom overlays
- Clone the repository
- Open .xcodeproj
- Run on simulator or device
- Subtitles are rendered in the SwiftUI layer using SDK callbacks
- Audio & subtitle data is controlled via SDK delegates
- For complete Source Code of the Demo Application check here
fastpix-ios-player-swiftui-demo
Click here for a detailed documentation on FastPix Player SDK for iOS.