This article details how to integrate CDN Mesh Delivery into your mobile app using Apple's TVML on tvOS.
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 1.6.0 + is recommended
To integrate StreamrootSDK into your Xcode project using CocoaPods, specify this in your Podfile
:
use_frameworks!
target ' <Your Target Name >'
pod 'AVPlayerDNAPlugin'
end
Then, run the following command:
$ pod update
Finally, open the generated Workspace.
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 Streamroot wrapper
Import DNAPlayerViewController.swift
and DNAInterfaceFactory.swift
classes in your project.
DNAPlayerViewController
: Wraps A View AVPlayerViewController with a DNACLient already setup. This class can be customized as neededDNAInterfaceFactory
: Allows to convert the DNAPlayerViewController into a TVML template
Register `DNAPlayerTemplate`
In the App delegate func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
methods, add those following line to register the template:
TVInterfaceFactory.shared().extendedInterfaceCreator = DNAInterfaceFactory()
TVElementFactory.registerViewElementClass(TVViewElement.self, elementName: DNAInterfaceFactory.templateName)
Use the `DNAPlayerTemplate`
The template can be created with the following function:
var createDNAPlayer = function(url, contentId) {
var dnaPlayerString = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<DNAPlayerTemplate url="${url}" contentId="${contentId}" displayStats="hidden" latency="30">
</DNAPlayerTemplate>
</document>`
var parser = new DOMParser();
var alertDoc = parser.parseFromString(dnaPlayerString, "application/xml");
return alertDoc
}
The template has 3 string attributes as it is defined in the DNAInterfaceFactory
class:
- url: url of the stream manifest
- contentId: Unique identifier for streams ContentId
- displayStats: Possible values can be
hidden
orshowed
- latency: To get the best offload capacity, we recommend setting 30s for latency.
Allow loading of local resources
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>NSAllowsLocalNetworking</key>
<true/>
</dict>