# Getting started with Millicast for iOS

## Usage

1. Follow our [Getting Started guide](https://optiview.dolby.com/docs/theoplayer/getting-started/sdks/ios/getting-started.md) to set up THEOplayer in your iOS app.
2. Add the `THEOplayer-Integration-Millicast` dependency to your project.
3. Add the `THEOplayerMillicastIntegration` to the player.
4. Add a `MillicastSource` to your player's source.

### Add the `THEOplayer-Integration-Millicast` dependency

Add the Millicast integration as a dependency in to your project:

**Swift Package Manager**

```swift
.package(url: "https://github.com/THEOplayer/theoplayer-sdk-apple.git", from: "8.10.0")
.product(name: "THEOplayerMillicastIntegration", package: "theoplayer-sdk-apple")
```

**Cocoapods**

```ruby
pod 'THEOplayer-Integration-Millicast', '~> 8.10'
```

### Add the Millicast SDK dependency

The Millicast integration requires the Millicast SDK as a direct dependency. The required version depends on your THEOplayer version:

| THEOplayer version | Millicast SDK version |
| ------------------ | --------------------- |
| 11.5.0+            | 2.6.x+                |
| 11.3.0 – 11.4.x    | 2.5.x+                |
| 10.11.0 – 11.2.x   | 2.5.3                 |
| 9.12.0 – 10.10.x   | 2.5.1                 |
| 9.7.0 – 9.11.x     | 2.4.3                 |
| 9.5.0 – 9.6.x      | 2.4.1                 |
| 8.10.0 – 9.4.x     | 2.2.0                 |

> **Note**
>
> If you are using CocoaPods, the `THEOplayer-Integration-Millicast` pod already specifies the Millicast SDK dependency, so you do not need to add it manually.

Add the Millicast SDK via Swift Package Manager:

```swift
.package(url: "https://github.com/millicast/millicast-sdk-swift-package.git", "2.6.0"..<"2.7.0")
.product(name: "MillicastSDK", package: "millicast-sdk-swift-package")
```

### Add the Millicast integration to the player

First import the integration into your project:

```swift
import THEOplayerMillicastIntegration
```

Create and add the `THEOplayerMillicastIntegration` to your `THEOplayer`:

```swift
let millicastIntegration = MillicastIntegrationFactory.createIntegration()
theoplayer.addIntegration(millicastIntegration)
```

### Add a `MillicastSource`

After setting up a `THEOplayer` in your app, set its source to a `SourceDescription` containing a `MillicastSource`. You'll need a Millicast account ID and stream name to identify your Millicast stream:

```swift
let millicastSource = SourceDescription(source: MillicastSource(src: "multiview", streamAccountId: "k9Mwad"))
theoplayer.source = millicastSource
```

Here `src` refers to the stream name. Make sure to replace the above `src` and `streamAccountId` with your own. If your source is a secure stream, then you will also need to add a subscriber token to the source as follows:

```swift
MillicastSource(src: ..., streamAccountId: ..., subscriberToken: "Your token")
```

### Add configuration

Optionally, you can provide additional configuration to the source, specific for working with Millicast streams. To configure these settings, add a `MCClientOptions` object as the `connectOptions` parameter of the source object and specify the options.

In the example below, the configuration is used to disable any audio from the Millicast stream. For an exhaustive list of these options, visit the [documentation](https://millicast.github.io/doc/latest/apple/documentation/millicastsdk/mcclientoptions).

```swift
let connectOptions: MCClientOptions = .init()
connectOptions.disableAudio = true
MillicastSource(src: ..., streamAccountId: ..., connectOptions: connectOptions)
```

### Background playback

In order to play Millicast sources in the background, ensure you've configured a `backgroundPlaybackDelegate` on the player. A simple example for always allowing background playback is shown below:

```swift
class BackgroundDelegate: BackgroundPlaybackDelegate {
    func shouldContinueAudioPlaybackInBackground() -> Bool {
        return true
    }
}
theoplayer.backgroundPlaybackDelegate = BackgroundDelegate()
```

## More information

* [API references](https://optiview.dolby.com/docs/theoplayer/v11/api-reference/ios/Millicast/index)
