# Apple AirPlay

# Features

  • Supports Apple AirPlay

# Plugin requirements

  • iOS 13 or higher
  • Xcode
  • Swift 5.5
  • ByteArkPlayerSDK version >= 0.2.1

# Plugin installation

CocoaPods (opens new window) is a dependency manager for Cocoa projects. Install with:

gem install cocoapods
1

To install the AirPlay Plugin with CocoaPods:

  1. Add the ByteArk Player SDK for iOS CocoaPods repo:
pod repo add byteark-player-sdk-ios-specs https://github.com/byteark/byteark-player-sdk-ios-specs.git
1
  1. Modify your Podfile by adding the following lines at the top:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/byteark/byteark-player-sdk-ios-specs.git'
1
2
  1. Add the plugin to your Podfile:
pod 'ByteArkPlayerSDKAirplayPlugin', '~> BYTEARK_PLAYER_SDK_AIRPLAY_PLUGIN_VERSION'
1

Replace BYTEARK_PLAYER_SDK_AIRPLAY_PLUGIN_VERSION with the version you wish to use.

  1. Run pod install:
pod install
1

Caution

CocoaPods installs the SDK from a private GitHub repository over SSH. If you have not configured an SSH key, follow Adding a new SSH key to your GitHub account (opens new window).

# Swift Package Manager

Use Swift Package Manager (SPM) to install ByteArkPlayerSDKAirplayPlugin.

  1. In Xcode, go to File > Add Packages.
  2. Enter https://github.com/byteark/byteark-player-sdk-ios-airplay-plugin.
  3. Select the version.
  4. Xcode will download the SDK in the background.

# Usage

import UIKit
import ByteArkPlayerSDK
import ByteArkPlayerSDKAirplayPlugin
class PlayerViewController: ByteArkPlayerViewController, ByteArkPlayerAirplayPluginDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()
    do {
      // Create the AirPlay config
      let airplayConfig = try ByteArkPlayerAirplayConfigBuilder().build()
      // Create the AirPlay plugin
      let airplayPlugin = ByteArkPlayerAirplayPlugin(with: airplayConfig)
      // Receive AirPlay events
      airplayPlugin.delegate = self
      // Build a player item
      let item = try ByteArkPlayerItemBuilder()
        .media(URL(string: "<MEDIA_URL>")!)
        .title("Big Buck Bunny")
        .build()
      // Configure the player with the AirPlay plugin
      let config = try ByteArkPlayerConfigBuilder()
        .item(item)
        .autoplay(true)
        .addPlugin(plugin: airplayPlugin, name: ByteArkPlayerAirplayPlugin.PluginName)
        .build()
      player.configure(with: config)
    } catch {
      print(error.localizedDescription)
    }
  }
  // MARK: - ByteArkPlayerAirplayPluginDelegate
  func airplayDidStart() {
    print("AirPlay did start.")
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

# Plugin APIs

The plugin exposes variables and delegate methods on its instance.

# Variables

Name Description
var delegate: ByteArkPlayerAirplayPluginDelegate? { get, set } Set the AirPlay plugin delegate

# Listen to plugin events

@objc public protocol ByteArkPlayerAirplayPluginDelegate {
  /// Fired when AirPlay starts
  @objc optional func airplayDidStart()
  /// Fired when AirPlay stops
  @objc optional func airplayDidStop()
}
1
2
3
4
5
6
7