This article details how to integrate CDN Mesh Delivery into your mobile app using Apple's AVPlayer on iOS.
Not into tutorials? |
Since DNA 2.15, due to the update of WebRTC, we no longer support iOS under version 10.
If you still require it, we recommend to stick to our SDK 3.12.x.
Project setup
CocoaPods
CocoaPods is a dependency manager for Cocoa projects.
Cocoapods 1.6.0 + is recommended
To integrate AVPlayerDNAPlugin into your Xcode project using CocoaPods, specify this in your Podfile
:
use_frameworks!
pod 'AVPlayerDNAPlugin', '~> 1.1.22'
Carthage
Add the dependencies to the Cartfile:
github "streamroot/avplayer-dna-plugin" ~> 1.1.22
Link the frameworks to your project:
Integrate Streamroot Plugin
Set the streamrootKey
In the Project Navigator, right click on "Info.plist", and "Open as" → "Source Code".
Add the following lines with the right parameters values:
<key>Streamroot</key>
<dict>
<key>Key</key>
<string>streamrootKey</string>
</dict>
Here, <streamrootKey>
refers to your Streamroot key that you will find in the Account section of the Streamroot Dashboard. If you don't have a Streamroot Key, you can register for a free trial account on our website.
Import the plugin
import AVPlayerDNAPlugin
Start and link the plugin to the player
do {
dnaPlugin = AVPlayerDNAPlugin(manifestUrl: <#ManifestUrl#>)
if let localPath = try dnaPlugin?.start() {
player = AVPlayer(url: localPath)
try dnaPlugin?.linkPlayer(player)
player?.play()
}
} catch let error {
// handle error
}
<
refers to the HLS #ManifestUrl#
>.m3u8
master playlist URL.
Add custom options
The plugin can be started with an optional configuration.
let config = DNAConfig()
config.streamrootKey = <#streamrootKey#>
config.latency = 30
config.contentId = <#ContentId#>
config.property = <#Property#>
To get the best offload capacity, we recommend setting 30s for latency
.
In order to improve the Mesh Delivery traffic offload, different buffer levels will be setted for each player.
Here, we will distribute the buffer target between 10 and the latency set above (30s recommended).
If no
<streamrootKey>
is passed, we will use the one in the Plist file.
Start and link the plugin to the player
do {
dnaPlugin = AVPlayerDNAPlugin(manifestUrl: <#ManifestUrl#>, config: config)
if let localPath = try dnaPlugin?.start() {
player = AVPlayer(url: localPath)
try dnaPlugin?.linkPlayer(player)
player?.play()
}
} catch let error {
// handle error
}
Stop the plugin
dnaPlugin?.stop()
Disable App Transport security
In the Project Navigator, right click on "Info.plist", and "Open as" → "Source Code".
Add the following lines with the right parameters values.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>