Set up the player

This page describes setting up and configuring the player within your iOS or tvOS application. When you incorporate the player using the SDK framework and its API, you can use its powerful features to enhance the playback experience for your users.

Add the player

iOS projects

Applies to: iOS

At the core of the iOS component of the Apple SDK is the FlowplayerView class, an implementation of the FlowplayerViewAPI protocol that provides a view component for the media player. When using this class, you can render the player within your user interface, and handle user interactions and visual customizations.

The FlowplayerView class extends the UIView object and manages content for a rectangular screen area. Since the FlowplayerView class inherits from the UIView object, it can be added to a UIView or UIViewController, as demonstrated in the examples in this section.

Add FlowplayerView using Storyboard

You can use this sample code to set up, load, and utilize the FlowplayerView using Storyboard.

Copy
Copied
import UIKit
import FlowplayerSDK

class MyViewController: UIViewController {

  @IBOutlet weak var flowplayerView: FlowplayerView!

  override func viewDidLoad() {
    super.viewDidLoad()

    flowplayerView.load(...)
  }
}

Add FlowplayerView programmatically

This example illustrates how to set up, load, and use the FlowplayerView using a programmatic approach.

Copy
Copied
import UIKit
import FlowplayerSDK

class MyViewController: UIViewController {

  private let flowplayerView = FlowplayerView()

  override func viewDidLoad() {
    super.viewDidLoad()
     // Set up the view
     view.addSubview(flowplayerView)
     flowplayerView.translatesAutoresizingMaskIntoConstraints = false
     NSLayoutConstraint.activate([
         flowplayer.centerXAnchor.constraint(equalTo: view.centerXAnchor),
         flowplayer.centerYAnchor.constraint(equalTo: view.centerYAnchor),
         flowplayer.heightAnchor.constraint(equalToConstant: 250),
         flowplayer.leadingAnchor.constraint(equalTo: view.leadingAnchor),
         flowplayer.trailingAnchor.constraint(equalTo: view.trailingAnchor)
      ])

    // Use the view
    flowplayerView.load(...)
  }
}

tvOS projects

Applies to: tvOS

At the core of the tvOS component of the Apple SDK is the FlowplayerManager object, which manages media playback, media assets, playback state, player state, and advertisements. You can think of this object as the manager of your AVPlayer instance. It wraps around the player and provides the methods and properties to manage your player instance.

With the following example, you can incorporate the player into your tvOS application using the FlowplayerManager class.

Copy
Copied
import UIKit
import FlowplayerSDK

class MyViewController: UIViewController {

  private var manager: FlowplayerManager
  private let player = AVPlayer()
  private let playerController = AVPlayerViewController()

  override func viewDidLoad() {
    super.viewDidLoad()

    manager = FlowplayerManager(avPlayer: player)

    present(playerController, animated: false) {
      self.manager.load(...)
    }
  }
}

Load your media files

Applies to: iOS and tvOS

To work with the player in your iOS or tvOS application, you need to define how the player loads media files.

By leveraging the FlowplayerAPI class, you can play media directly from a specific media URL. You can configure the player to use a local or remote URL. To load external media, initialize the player with an MediaExternal instance as shown in the following example.

Copy
Copied
let externalMedia = MediaExternal(url: URL(string: "https://link.to.a.media.file")!)
flowplayer.load(external: externalMedia)

These properties are available when working with a MediaExternal structure.

Property Description
adSchedule Optional ad schedule to display ads during external media playback. For more information about using ad schedules with external media, see iOS Advertisements and tvOS Advertisements.
preferredPeakBitRate Optional Double representing the preferred peak bitrate for the media item's playback. If not provided, the default bitrate is used.
url URL representing the location of the external media item.