Playback

In the Playback section we list the common features shared by all player engines (PlayerEngine.apple)

Basic playback

An example project of basic HLS playback is provided as part of the PRESTOplay SDK. The example is located in the Examples folder and can be opened with Xcode.

import PRESTOplay
import CastlabsApple

// Initialize the SDK and register the plugins
_ = PRESTOplaySDK.shared.register("LICENSE", [HLSPlugin()]) 

// Create the player
var player = PRESTOplaySDK.shared.player()

guard let contentURL = URL(string: "https://example.com/master.m3u8")
else { return }

// Configure the player
let config = PlayerConfiguration(with: contentURL)
player.load(config: config)

player.onState = { previous, state in
  // Handle player state changes
  switch state {
  case .ready:
    print("Player ready")
  // handle other states ...
  }

  if let error = state.playerError {
    print("Error \(error)")
  }
}

// Attach the player to the view
player.attach(to: view.layer)

// Start playback
player.open(autoplay: true)

Video gravity

Video gravity determines how the video content is scaled or stretched within the player bounds.

The player layer supports the following video gravity values:

  • AVLayerVideoGravity.resizeAspect player should preserve the video’s aspect ratio and fit the video within the bounds,

  • AVLayerVideoGravity.resizeAspectFill player should preserve the video’s aspect ratio and fill the bounds,

  • AVLayerVideoGravity.resize video should be stretched to fill the bounds

Phone call

By default the player is paused when a phone call has started and resumes playback when a phone call ends.

Airplay

Airplay is supported and no changes are required from the SDK user. Specifically:

  • HLS streams are natively supported, i.e. you only need to switch on Airplay on your device
  • MPEG-DASH requires to switch on Airplay and to active the screen mirroring

By default, AirPlay is disabled for DRM-encrypted content. To enable, set preventSecondScreenPlayback to false in the DRM configuration.

playerConfiguration.drmConfiguration?.preventSecondScreenPlayback = false

If the content is encrypted with an authentication token (drmConfiguration.authToken), you must set the user token obtained from your DRM provider.

player = PRESTOplaySDK.shared.player()
playerConfiguration.userToken = userToken
player.load(config: playerConfiguration)