> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://fastpix.com/docs/video-data/monitors/avplayer/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://fastpix.com/_mcp/server. # Monitor AVPlayer (iOS) FastPix Video Data SDK with [AVPlayer](https://github.com/FastPix/iOS-data-avplayer-sdk) enables tracking of key video performance metrics, making the data readily available on the FastPix dashboard for monitoring and analysis. While the SDK is developed in Swift, the published SPM package currently includes only the Swift output. **Key features:** * See how users interact with your videos. * Track real-time metrics like bitrate, buffering, startup, render quality, and failures. * Identify and fix video delivery bottlenecks on iOS. * Get detailed error reports to quickly identify and fix playback issues. * Customize tracking to match your specific business needs. * Handle errors with robust reporting and diagnostics. * View and compare metrics to make data-driven decisions. #### Support for tvOS Alongside iOS, the FastPix Video Data Core SDK also supports tvOS, allowing you to collect detailed playback analytics from your **Apple TV** apps when using AVPlayer. You can track viewer engagement, playback quality, errors, and custom events on Apple TV just as you do on iOS. We’ve tested the SDK on tvOS to ensure a smooth experience, but if you encounter any issues or have questions, feel free to reach out to us. \ #### [Step 1](/video-data/monitors/avplayer#step-1-install-and-setup) Install and setup #### [Step 2](/video-data/monitors/avplayer#step-2-import-the-sdk) Import the SDK #### [Step 3](/video-data/monitors/avplayer#step-3-basic-integration) Basic integration #### [Step 4](/video-data/monitors/avplayer#step-4--include-metadata-for-tracking) Include metadata #### [Step 5](/video-data/monitors/avplayer#step-5-emit-custom-events) Emit custom events #### [Detailed example](/video-data/monitors/avplayer#detailed-example-to-configure-avplayer) Configure AVPlayer * [Step 1](/video-data/monitors/avplayer#step-1-install-and-setup) Install and setup * [Step 2](/video-data/monitors/avplayer#step-2-import-the-sdk) Import the SDK * [Step 3](/video-data/monitors/avplayer#step-3-basic-integration) Basic integration * [Step 4](/video-data/monitors/avplayer#step-4--include-metadata-for-tracking) Include metadata * [Step 5](/video-data/monitors/avplayer#step-5-emit-custom-events) Emit custom events * [Detailed example](/video-data/monitors/avplayer#detailed-example-to-configure-avplayer) Configure AVPlayer \ ## Prerequisites To track and analyze video performance, initialize the SDK with your Workspace key. Learn about [Workspaces](/getting-started/set-up-a-workspace). 1. Access the FastPix [Dashboard](https://dashboard.fastpix.com/): Log in and navigate to the Workspaces section. \ 2. Locate Your Workspace Key: Copy the Workspace Key for client-side monitoring. Include this key in your Swift code on every page where you want to track video performance. \ ## Step 1: Install and setup You can integrate the SDK into your project using Swift Package Manager (SPM). Follow these steps to add the package to your iOS project. * Open your Xcode project and navigate to: File → Add Packages * Enter the repository URL for the FastPix SDK: [https://github.com/FastPix/iOS-data-avplayer-sdk](https://github.com/FastPix/iOS-data-avplayer-sdk) * Choose the latest stable version and click Add Package. * Select the target where you want to use the SDK and click Add Package. \ ## Step 2: Import the SDK ```swift import FastpixVideoDataAVPlayer ``` \ ## Step 3: Basic integration Ensure that the `workspace_id` is provided, as it is a mandatory field for FastPix integration, uniquely identifying your workspace. Install and import AVFoundation into your project, and create an `avplayer` instance to bind it to. If you are using any other custom player then create an instance of that player. Next, create an instance of `initAvPlayerTracking` for tracking the analytics. Once the video URL is loaded and playback has started, the SDK will begin tracking the analytics. \ ```swift import FastpixVideoDataAVPlayer let fpDataSDK = initAvPlayerTracking() let customMetadata = [ "data": [ workspace_id: "WORKSPACE_KEY", // Unique key to identify your workspace (replace with your actual workspace key) video_title: "Test Content", // Title of the video being played (replace with the actual title of your video) video_id: "f01a98s76t90p88i67x", // A unique identifier for the video (replace with your actual video ID for tracking purposes) ] ] // Track AVPlayer Layer fpDataSDK.trackAvPlayerLayer( playerLayer: playerLayer, // The AVPlayerLayer instance managing the playback customMetadata: customMetadata ) // Track AVPlayer fpDataSDK.trackAvPlayer( player: player, // The AVPlayer instance managing the playback customMetadata: customMetadata ) // Track AVPlayer Controller fpDataSDK.trackAvPlayerController( playerController: playerController, // The AVPlayerViewController instance managing the playback customMetadata: customMetadata ) ``` \ ## Step 4: Include metadata for tracking Check out the [user-passable metadata](/video-data/use-custom-dimensions) documentation to see the metadata supported by FastPix. You can use custom metadata fields like **custom\_1** to **custom\_10** for your business logic, giving you the flexibility to pass any required values. Named attributes, such as **video\_title** and **video\_id**, can be passed directly as they are. \ ```swift let customMetadata = [ "data": [ workspace_id: "WORKSPACE_KEY", // Unique key to identify your workspace (replace with your actual workspace key) video_title: "Test Content", // Title of the video being played (replace with the actual title of your video) video_id: "f01a98s76t90p88i67x", // A unique identifier for the video (replace with your actual video ID for tracking purposes) viewer_id: "user12345", // A unique identifier for the viewer (e.g., user ID, session ID, or any other unique value) video_content_type: "series", // Type of content being played (e.g., series, movie, etc.) video_stream_type: "on-demand", // Type of streaming (e.g., live, on-demand) // Custom fields for additional business logic custom_1: "", // Use this field to pass any additional data needed for your specific business logic custom_2: "", // Use this field to pass any additional data needed for your specific business logic // Add any additional metadata ] ] ``` \ > **DEVELOPMENT TIP** > > Keep metadata consistent across different video loads to make comparison easier in your analytics dashboard. \ \ ## Step 5: Emit custom events \ ### Changing video streams in player When playing multiple videos back-to-back, it's essential to notify the FastPix SDK whenever a new video starts to ensure accurate tracking. You should signal a new source in the following scenarios: * The player advances to the next video in a playlist. * The user selects a different video to play. To inform the FastPix SDK of a new view, emit a `videoChange` event immediately after loading the new video source: \ ```swift import FastpixVideoDataAVPlayer let fpDataSDK = initAvPlayerTracking() fpDataSDK.trackAvPlayerLayer( playerLayer: playerView.renderingView.playerLayer, customMetadata: customMetadata ) fpDataSDK.dispatchEvent(event: "videoChange", metadata: [ video_id: "123def", // Unique identifier for the new video video_title: "My Great Video", // Title of the new video video_series: "Weekly Great Videos", // Series name if applicable // ... and other metadata ]) ``` \ > **PLEASE NOTE** > > Always ensure that this event is dispatched right after the new source is loaded to maintain accurate tracking. \ ## Detailed example to configure AVPlayer Here’s an example to help you integrate the FastPix Data SDK with AVPlayer.\ You can use this code in your application: \ ```swift // import the SDK import FastpixVideoDataAVPlayer // create reference to the sdk let fpDataSDK = initAvPlayerTracking() // Function to integrate SDK into your iOS Project func getVideoFPData() { let customMetadata: [String: Any] = [ "video_title": videoTitle, "video_id": movieID, "workspace_id": “workspace_key”, "video_source_url" : videoUrlStrng, "player_name": "AVPlayer", "video_content_type": Videotype, "player_poster": playerPosterURL, "custom_1": Videotype, "custom_2": videoContentAvailability, "custom_3": videoUrlStrng, "custom_4": movieID, "custom_5": playerPosterURL, "custom_6": skipIntroStart, "custom_7": skipIntroEnd ] let userPassableData = ["configDomain": "beacon_domain", "data": customMetadata] as [String : Any] fpDataSDK.trackAvPlayerLayer(playerLayer: playerView.renderingView.playerLayer, customMetadata: userPassableData) } // Example to integrate getVideoFPData() where the player is being initialized in your iOS Project func initiatePlayer(videourl:String) { if let url = URL.init(string:videourl) { subtitlesLanguages.removeAll() let item = VersaPlayerItem(url: url) item.isEncrypted = true controls.handler.decryptionDelegate = self playerView.set(item: item) if resumeTime > 0 { playerView.player.seek(to: CMTime(seconds: Double(resumeTime), preferredTimescale: 1)) } if let group = playerView.player?.currentItem?.asset.mediaSelectionGroup(forMediaCharacteristic: .legible) { // Print its options. print(group.options) for option in group.options { subtitlesLanguages.append(option.displayName) print("Option: \(option.displayName)") } if subtitlesLanguages.count > 0 { if subtitlesLanguages.count == 1 && subtitlesLanguages[0] == "CC"{ controls.button_subtitles?.isHidden = true }else{ controls.button_subtitles?.isHidden = false } }else{ controls.button_subtitles?.isHidden = true } } getVideoFPData() displaySubtitles() } } ``` --- \ ## Release notes For a complete release history, including new features, improvements, and bug fixes, see the [FastPix AVPlayer (iOS) SDK CHANGELOG on GitHub](https://github.com/FastPix/iOS-data-avplayer-sdk/blob/main/CHANGELOG.md). > The single API stack for video: upload, encode, stream, secure, and analyze video at any scale. Explore guides, API references, and SDKs.