Using the player

This section gives a brief introduction to the player API in order to help you to get quickly started.

To enable AVPlayer to play audio on physical devices you must add the following code snippet before starting any video/audio playback.

try! AVAudioSession.sharedInstance().setCategory(.playback)

Add the player to UIView

The core of the Flowplayer SDK is the FPFlowplayerViewController which inherits from UIViewController and can therefore be added to a UIView or to a UIViewController in an ordinary fashion like so:

import UIKit
import Flowplayer

class PlayerViewController: UIViewController {
    @IBOutlet var containerView: UIView!

    private let flowplayerViewController = FPFlowplayerViewController()

    override func viewDidAppear(_ animated: Bool) {
        // Add to a container view or directly to your UIViewController's view.

You can also add FPFlowplayerViewController to your Storyboard similar to any other UIViewController.

Prepare player

FPFlowplayerViewController can play media either by fetching a so-called Flowplayer config or directly from a media URL that you specify.

In the first scenario, the player needs to be prepared with a Flowplayer mediaId and a playerId. This is achieved by preparing the player with a FPFlowplayerMedia instance. The player will then fetch the Flowplayer config which contains the media URL, the ad schedule (if any), and branding-related information.

To utilize the Flowplayer Analytics you must use Flowplayer platform mediaIds (either videos hosted on our platform or registered remote assets ) Configuring direct stream urls will not trigger Analytics. You must also load the Analytics plugin.

let fpMedia = FPFlowplayerMedia(mediaId: "some-media-id", playerId: "some-player-id")
flowplayerViewController.prepare(flowplayerMedia: fpMedia, autoStart: true)

In a similar way, the player can be prepared with a local or remote media URL. This is possible by preparing the player with an ExternalVideo instance as shown below. An FPExternalMedia may optionally contain an FPAdSchedule, as well. For more information about ads, see section Advertisement.

let externalMedia = FPExternalMedia(mediaUrl: URL(string: "")!)
flowplayerViewController.prepare(externalMedia: externalMedia, autoStart: true)

Limiting video bitrate

When playing HLS media you can configure the preferred maximum peak bitrate.

You can achieve this by defining the preferred peak bitrate as a double when constructing the media:

// Flowplayer media
let fpMedia = FPFlowplayerMedia(
    mediaId: "some-media-id",
    playerId: "some-player-id",
    preferredPeakBitRate: 500_000

// ExternalMedia
let externalMedia = FPExternalMedia(
    mediaUrl: URL(string: "")!,
    preferredPeakBitRate: 500_000