tvOS Setup

Getting Started

The THEOplayer tvOS SDK can be used from within both a client-server app project or a traditional app project.

With a Client-Server App

  1. In the target's General tab, in the Embedded Binaries click (+) and select the THEOplayerSDK.framework
  2. import THEOplayerSDK
  3. Declare a player variable and pass it the TVApplicationController instance
    var theoplayer = THEOplayer(appController: appController)
  4. Position and size your player
    theoplayer.frame = CGRect(x: 0, y: 0, width: 1280, height: 720)
  5. Add the player to your controller's view hierarchy
    theoplayer.addAsSubview(of: controller.view)

 

With a Traditional App

  1. In the target's General tab, in the Embedded Binaries click (+) and select the THEOplayerSDK.framework
  2. import THEOplayerSDK
  3. Prepare THEOplayer before instantiating it with your view controller, e.g. in the AppDelegate's application(_:didFinishLaunchingWithOptions:) method.
    THEOplayer.prepare(withFirstViewController: UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController())
  4. Declare a player variable with a frame
    var theoplayer = THEOplayer(with: CGRect(x: 0, y: 0, width: 1280, height: 720))
  5. Add the player to your controller's view hierarchy
    theoplayer.addAsSubview(of: controller.view)

Controlling the player

Once a player is created and set in your view, you can start interacting with the player instance using the THEOplayer API.

Setting a source

Create a SourceDescription object and set the player's source

let source = SourceDescription(sources: TypedSource(src: "https://www.examples.com/index.m3u8", type: "application/x-mpegurl"))
theoplayer.source = source

 

Add a player event listener

This example shows you how to listen to the player play event.

var playListener = theoplayer.addEventListener(type: PlayerEventTypes.PLAY, listener: handlePlayEvent)

func handlePlayEvent(event : PlayEvent) {
    print("Received \(event.type) event at \(event.currentTime)")
}

 

Remove a player event listener

theoplayer.removeEventListener(type: PlayerEventTypes.PLAY, listener: playListener)