Getting Started

The following tutorial will walk you through adding the Bitmovin Player SDK to a new or existing Xcode Project. If you're migrating from AVPlayer to Bitmovin Player, check out our migration guide instead.

Step 1: Add the SDK to your Project

You have several options for integrating the Player SDK into your project:

Using CocoaPods

Add the following lines to the Podfile of your project and replace the Version Number with the desired version of the SDK. All available versions are listed in the CocoaPods repository.
Execute pod repo update first to add the new source, then execute pod install to install the new BitmovinPlayer dependency.

source 'https://github.com/bitmovin/cocoapod-specs.git'
pod 'BitmovinPlayer', 'Version Number'

Using Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift frameworks. It integrates with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Using Xcode

To integrate using Xcode 14.1 open your Project file and specify it in Project > Package Dependencies using the following URL:

https://github.com/bitmovin/player-ios.git

Using Package.swift

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift file and replace the Version Number with the desired version of the SDK.

.package(url: "https://github.com/bitmovin/player-ios.git", exact: "Version Number")

Then specify BitmovinPlayer as a dependency of the desired target. Here is an example of a Package.swift file:

let package = Package(
  ...
  dependencies: [
    .package(url: "https://github.com/bitmovin/player-ios.git", exact: "Version Number")
  ],
  targets: [
    .target(name: "<NAME_OF_YOUR_PACKAGE>", dependencies: [.product(name: "BitmovinPlayer", package: "player-ios")])
  ]
  ...
)

:warning: Note: Executing swift build from the command line is currently not supported. Open the Package in Xcode if you are developing another Package depending on BitmovinPlayer.

Adding the SDK to your Project directly

As an alternative to CocoaPods, you can download all the needed XCFramework releases from our CDN. You can find the URLs to all Player related XCFrameworks in the .podspec file of the desired SDK version in our CocoaPods repository:

https://cdn.bitmovin.com/player/ios_tvos/VERSION_NUMBER/BitmovinPlayer-CocoaPods.zip

From Player version 3.42.0 onwards, it is required to also include the XCFramework of our AnalyticsCollector. The URL to the Analytics XCFramework can be found in the .podspec file of the desired SDK version in our CocoaPods repository (Note: the minimum required version is 3.0.0):

https://cdn.bitmovin.com/analytics/ios_tvos/VERSION_NUMBER/BitmovinAnalyticsCollector.zip

Then, using Xcode, just drag and drop all downloaded XCFrameworks into your project.

Step 2: Set up the Player

Configure the player license key

Add your player license key to the <dict> in the Info.plist:

<key>BitmovinPlayerLicenseKey</key>
<string>PLAYER_LICENSE_KEY</string>

Alternatively, you can also add the license key programmatically to the PlayerConfig via PlayerConfig.key.

Create the Player

You can create a Player instance with analytics tracking either with the default configuration,

// Enable Analytics by creating an AnalyticsConfig with your license key
let analyticsConfig = AnalyticsConfig(licenseKey: "<ANALYTICS_LICENSE_KEY>")

// Player using a default config
let player = PlayerFactory.createPlayer(
  analytics: .enabled(analyticsConfig: analyticsConfig)
)

or using a custom config:

// Or with a explicit PlayerConfig
let playerConfig = PlayerConfig()
playerConfig.key = "<PLAYER_LICENSE_KEY>" // Only needed if the license key was not added to the Info.plist file

let player = PlayerFactory.createPlayer(
    playerConfig: playerConfig,
    analytics: .enabled(analyticsConfig: analyticsConfig)
)

Configure the Source

Creating a SourceConfig based on a given Stream URL:

// Create the HLS stream URL
guard let streamUrl = URL(string: "https://cdn.bitmovin.com/content/art-of-motion/m3u8s/playlist.m3u8") else {
    return
}

// Create a SourceConfig
let sourceConfig = SourceConfig(url: streamUrl, type: .hls)

// Optionally set additional properties
sourceConfig.title = "Art of motion"

Load the Source

Load the created Source into the Player:

// Create a Source from the SourceConfig
let source = SourceFactory.createSource(from: sourceConfig)

player.load(source: source)

Note: When there is no need to access the Source instance before loading it, it is also possible to directly load a SourceConfig into the Player:

player.load(sourceConfig: sourceConfig)

Create a PlayerView using SwiftUI or UIKit

Create a view that is provided by the SDK with either SwiftUI or UIKit. This view will be used for rendering the video:

// Create the VideoPlayerView where the video will be rendered
VideoPlayerView(player: player)
// Create a PlayerView
let playerView = PlayerView(player: player, frame: view.bounds)

// Depending on your App layout you might want to set the autoresizingMask (recommended)
playerView.autoresizingMask = [.flexibleHeight, .flexibleWidth]

// Adding the view to the a container View
playerContainerView.addSubview(playerView)
playerContainerView.bringSubview(toFront: playerView)

See our examples for more details. There, you can find simple SwiftUI sample applications, including BasicPlayback for iOS, BasicPlaybackTV for tvOS and BasicPlaybackVisionOS for visionOS. For UIKit support, have a look at our BasicUIKit sample for iOS and BasicUIKitTV sample for tvOS.

See listening to events for details on how to get notified about certain events from the Player.

Step 3: Configure your Player and Analytics License

Allowlist your Bundle Identifiers

In order to use the player with analytics in your app, you have to allowlist the bundle identifier of your app into which you are integrating the SDK. This is a security mechanism and protects your license from being used elsewhere.

Allowlisting can be done in the Dashboard under Player > Licenses and Analytics > Licenses.

Summary

In this tutorial, you've learned how to add the Bitmovin Player SDK to your project, set up the player and analytics license, and how to configure and use the Player.

Next, you can

  • browse our API reference.
  • download fully working examples and explore more features in our GitHub repository.
  • choose additional platforms to deploy on in our Getting Started Hub and try our no-code wizards.
  • get real-time insights into your Player via our Analytics Dashboard.
  • see if some of the questions you might have are answered in our Community and ask your own!