Add player to your view
Use the following steps and code examples to add a player to the ViewController in your app:
- In your ViewController class import TargetVideoSDKtvOS
- Declare a variables TargetVideoPlayer and PlayerBuilder.
- Init your PlayerBuilder with selected settings and asign your viewController and view to it.
- Run PlayerBuilder method .build() to initialize your player.
- After the view appears, in viewDidAppear() or on a button action call TargetVideoPlayer method .loadVideo to show player with selected video, or .loadPlaylist to show your playlist.
import UIKit
import TargetVideoSDKtvOS
class ViewController: UIViewController {
var player: TargetVideoPlayer?
var builder: PlayerBuilder?
override func viewDidLoad() {
super.viewDidLoad()
builder = PlayerBuilder(parentVC: self, playerView: self.view)
player = builder?.build()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
player?.loadVideo(playerId: 0, videoId: 0)
}
@IBAction func showPlayer() {
player?.loadPlaylist(playerId: 0, playlistId: 0)
}
}
Updated about 2 months ago
What’s Next