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 Player SDK to your Project directly

As an alternative to CocoaPods, you can download the XCFramework release from our CDN. You can find the URL to the XCFramework in the .podspec file of the desired SDK version in our CocoaPods repository:

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

Then, using Xcode, just drag and drop the downloaded XCFramework into your project.

Step 2: Set up the Player

Configure the license key

Add your 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 either with the default configuration,

// Player using a default config
let player = PlayerFactory.create()

or using a custom config:

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

let player = PlayerFactory.create(playerConfig: playerConfig)

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.create(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

Create a view (provided by the SDK) which will be used for rendering the video:

// 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)

Step 3: Configure your Player License

Allowlist your Bundle Identifiers

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

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

Summary

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