GuidesAPI ReferenceRelease Notes
HomeLog InHome
Guides

AirPlay

The videos player supports AirPlay, allowing video and audio to be cast to external AirPlay-compatible devices such as Apple TV or AirPlay 2 speakers via the system route picker. While casting is active, the in-app player displays an AirPlay indicator overlay in place of the video.

App Setup

Two steps are required before AirPlay will function:

  1. Add NSLocalNetworkUsageDescription to your app's Info.plist.
  2. Enable Audio, AirPlay, and Picture in Picture under Background Modes in your Xcode project's Signing & Capabilities tab.
📘

The SDK validates the NSLocalNetworkUsageDescription key at runtime. In Debug builds a missing key causes a fatal error; in Release builds AirPlay is silently disabled.

Entry Point

Access AirPlay functionality through the castingManager on the Blaze.shared singleton:

Blaze.shared.castingManager

BlazeCastingManager

MemberTypeDescription
delegateBlazeCastingDelegateAssign to receive casting state callbacks
stopActiveCastingSession()methodStop AirPlay and return to local playback

Observing AirPlay State

Assign a BlazeCastingDelegate to receive callbacks whenever an AirPlay session starts or stops. Callbacks are always delivered on the main thread.

Blaze.shared.castingManager.delegate = BlazeCastingDelegate(
    onCastingStateChanged: { playerType, sourceId, newState in
        // playerType: BlazePlayerType — which player triggered the change
        // sourceId: String? — optional entry-point identifier
        // newState: BlazeCastingState (.on / .off)
    }
)

Parameters:

  • playerType: BlazePlayerType — identifies which player type (.videos, .moments, .stories) triggered the casting state change, allowing the host app to respond per player context.
  • sourceId: String? — the optional entry-point identifier passed when the player was opened.
  • newState: BlazeCastingState — the new casting state (.on when connected to an AirPlay device, .off when playback returns to the device).

BlazeCastingState

public enum BlazeCastingState: String {
    case on   // Connected to an external AirPlay device
    case off  // Local playback
}

Button Styling

The AirPlay button is accessible via BlazeVideosPlayerStyle.buttons.airPlay and uses the BlazeVideosPlayerButtonStyle type.

Defaults by player mode:

Player ModeAirPlay Button Visible by Default
Full-screenYes
InlineNo
var playerStyle = BlazeVideosPlayerStyle.base()
playerStyle.buttons.airPlay.isVisible = true
playerStyle.buttons.airPlay.width = 44
playerStyle.buttons.airPlay.height = 44
playerStyle.buttons.airPlay.color = .white
playerStyle.buttons.airPlay.isVisibleForAds = false

See BlazeVideosPlayerButtonStyle for the full list of configurable properties.

Behavior Notes

  • AirPlay indicator overlay — while an AirPlay session is active, the SDK displays a system AirPlay indicator in the player view in place of the video content.
  • Stopping casting programmatically — call Blaze.shared.castingManager.stopActiveCastingSession() to end the active AirPlay session and return to local playback from your own code.
  • Player-type awareness — the delegate callback reports the BlazePlayerType that triggered the state change, so the host app can respond differently depending on which player is casting.

Usage Examples

Observing AirPlay Events

Blaze.shared.castingManager.delegate = BlazeCastingDelegate(
    onCastingStateChanged: { playerType, sourceId, newState in
        switch newState {
        case .on:
            print("AirPlay started for player: \(playerType), source: \(sourceId ?? "unknown")")
        case .off:
            print("AirPlay ended for player: \(playerType)")
        }
    }
)

Stopping an Active AirPlay Session

// Return to local playback (e.g., when the user navigates away from your media screen)
Blaze.shared.castingManager.stopActiveCastingSession()

Customizing the AirPlay Button

var playerStyle = BlazeVideosPlayerStyle.base()

// Show the AirPlay button in both full-screen and inline modes
playerStyle.buttons.airPlay.isVisible = true
playerStyle.buttons.airPlay.color = .systemBlue
playerStyle.buttons.airPlay.width = 44
playerStyle.buttons.airPlay.height = 44

Blaze.shared.setDefaultVideosPlayerStyle(playerStyle)

Hiding the AirPlay Button During Ads

var playerStyle = BlazeVideosPlayerStyle.base()
playerStyle.buttons.airPlay.isVisibleForAds = false

Blaze.shared.setDefaultVideosPlayerStyle(playerStyle)

Did this page help you?