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:
- Add
NSLocalNetworkUsageDescriptionto your app'sInfo.plist. - Enable Audio, AirPlay, and Picture in Picture under Background Modes in your Xcode project's Signing & Capabilities tab.
The SDK validates theNSLocalNetworkUsageDescriptionkey 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.castingManagerBlazeCastingManager
| Member | Type | Description |
|---|---|---|
delegate | BlazeCastingDelegate | Assign to receive casting state callbacks |
stopActiveCastingSession() | method | Stop 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 (.onwhen connected to an AirPlay device,.offwhen 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 Mode | AirPlay Button Visible by Default |
|---|---|
| Full-screen | Yes |
| Inline | No |
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 = falseSee 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
BlazePlayerTypethat 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)Updated about 2 months ago
