Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.build/
DerivedData/
*.xcuserstate
xcuserdata/
231 changes: 231 additions & 0 deletions Examples/SwiftUI/FastPixPlayerExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 77;
objects = {

/* Begin PBXBuildFile section */
A0000010 /* FastPixPlayerSDK in Frameworks */ = {isa = PBXBuildFile; productRef = A0000009 /* FastPixPlayerSDK */; };
/* End PBXBuildFile section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
A0000006 /* FastPixPlayerExample */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = FastPixPlayerExample; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
A0000003 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A0000010 /* FastPixPlayerSDK in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
A0000000 = {
isa = PBXGroup;
children = (
A0000006 /* FastPixPlayerExample */,
A0000007 /* Products */,
);
sourceTree = "<group>";
};
A0000007 /* Products */ = {
isa = PBXGroup;
children = (
A0000005 /* FastPixPlayerExample.app */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
A0000004 /* FastPixPlayerExample */ = {
isa = PBXNativeTarget;
buildConfigurationList = A000000C /* Build configuration list for PBXNativeTarget "FastPixPlayerExample" */;
buildPhases = (
A0000002 /* Sources */,
A0000003 /* Frameworks */,
A0000001 /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
A0000006 /* FastPixPlayerExample */,
);
name = FastPixPlayerExample;
packageProductDependencies = (
A0000009 /* FastPixPlayerSDK */,
);
productName = FastPixPlayerExample;
productReference = A0000005 /* FastPixPlayerExample.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
A0000008 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1700;
LastUpgradeCheck = 1700;
TargetAttributes = {
A0000004 = {
CreatedOnToolsVersion = 17.0;
};
};
};
buildConfigurationList = A000000B /* Build configuration list for PBXProject "FastPixPlayerExample" */;
compatibilityVersion = "Xcode 15.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = A0000000;
minimizedProjectReferenceProxies = 1;
packageReferences = (
A0000000A /* XCLocalSwiftPackageReference "../.." */,
);
productRefGroup = A0000007 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
A0000004 /* FastPixPlayerExample */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
A0000001 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
A0000002 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
A000000D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
A000000E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
};
name = Release;
};
A000000F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fastpix.FastPixPlayerExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
A0000011 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.fastpix.FastPixPlayerExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
A000000B /* Build configuration list for PBXProject "FastPixPlayerExample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A000000D /* Debug */,
A000000E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A000000C /* Build configuration list for PBXNativeTarget "FastPixPlayerExample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A000000F /* Debug */,
A0000011 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
A0000000A /* XCLocalSwiftPackageReference "../.." */ = {
isa = XCLocalSwiftPackageReference;
relativePath = "../..";
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
A0000009 /* FastPixPlayerSDK */ = {
isa = XCSwiftPackageProductDependency;
productName = FastPixPlayerSDK;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = A0000008 /* Project object */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions Examples/SwiftUI/FastPixPlayerExample/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import SwiftUI
import AVKit
import FastPixPlayerSDK

// MARK: - Configuration
// Replace these placeholders with your own values before running.
enum FastPixConfig {
/// Your FastPix workspace key. Find it in the FastPix dashboard under
/// Workspaces (https://dashboard.fastpix.io). A placeholder key still
/// wires the analytics pipeline — the backend just rejects its beacons.
static let workspaceKey = "WORKSPACE_KEY"

/// The playback ID of the video to play, from your FastPix dashboard.
/// Defaults to a public FastPix demo asset so the example runs as-is.
static let playbackID = "7c8d5087-edf7-462f-a1b3-e2fbd30747fa"
}

// MARK: - Player + SDK owner
// SwiftUI View structs are recreated on every render, so the player and the
// FastPix Data SDK attached to it must live in an ObservableObject that
// survives re-renders (held as @StateObject by the View).
final class PlayerModel: ObservableObject {
let controller = AVPlayerViewController()

init() {
// Attach FastPix analytics before preparing playback.
controller.enableAnalytics(metadata: [
"workspace_id": FastPixConfig.workspaceKey,
"video_title": "FastPix SwiftUI Example",
"viewer_id": "swiftui-demo-user",
"video_stream_type": "on-demand",
])
controller.prepare(
playbackID: FastPixConfig.playbackID,
playbackOptions: PlaybackOptions(streamType: "on-demand")
)
}

func play() { controller.play() }
func pause() { controller.pause() }

deinit {
// Releasing the controller tears down the player and detaches the SDK.
controller.pause()
}
}

// MARK: - SwiftUI bridge for AVPlayerViewController
struct FastPixPlayerView: UIViewControllerRepresentable {
let controller: AVPlayerViewController
func makeUIViewController(context: Context) -> AVPlayerViewController { controller }
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {}
}

struct ContentView: View {
@StateObject private var model = PlayerModel()

var body: some View {
FastPixPlayerView(controller: model.controller)
.ignoresSafeArea()
.onAppear { model.play() }
.onDisappear { model.pause() } // teardown on disappear
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct FastPixPlayerExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
40 changes: 40 additions & 0 deletions Examples/SwiftUI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# FastPix iOS Player — SwiftUI Example

A minimal, self-contained SwiftUI app that plays a video with the FastPix iOS
Player and attaches the FastPix Data (analytics) SDK. Copy this folder into
your own project, or open it as-is.

## Run it

1. Open `FastPixPlayerExample.xcodeproj` in Xcode.
2. Select an iOS Simulator (or your device) and press **Run**.

The project references the `FastPixPlayerSDK` package from this repository via a
local package reference (`../..`), so no extra setup is needed.

## Configure

Both values live at the top of [`ContentView.swift`](FastPixPlayerExample/ContentView.swift):

```swift
enum FastPixConfig {
static let workspaceKey = "WORKSPACE_KEY" // ← replace
static let playbackID = "7c8d5087-edf7-462f-a1b3-e2fbd30747fa" // demo asset
}
```

- **`workspaceKey`** — get yours from the [FastPix dashboard](https://dashboard.fastpix.io)
under Workspaces. The bundled placeholder still exercises the analytics
pipeline; the backend simply rejects its beacons until you set a real key.
- **`playbackID`** — defaults to a public FastPix demo video so the example
runs unchanged. Replace it with your own playback ID.

## How it works

- `PlayerModel` (an `ObservableObject`) owns the `AVPlayerViewController` so the
player and the attached SDK survive SwiftUI re-renders.
- `enableAnalytics(metadata:)` attaches the Data SDK **before** `prepare(...)`.
- `FastPixPlayerView` bridges the controller into SwiftUI via
`UIViewControllerRepresentable`.
- Playback starts in `.onAppear` and is torn down in `.onDisappear` / the
model's `deinit`.