Delegate Handlers
BlazeInlinePlayerDelegate
BlazeInlinePlayerDelegate is a struct that implements handlers for various player events. You can set handlers for these events using the inlinePlayerDelegate view modifier.
Setting inlinePlayerDelegate
func inlinePlayerDelegate(_ delegate: BlazeInlinePlayerDelegate) -> BlazeSwiftUIVideosInlinePlayerViewSets the delegate that receives notifications about player events, including data loading, player appearance/dismissal, and user interactions.
Parameters:
- delegate: The delegate object that implements the BlazeInlinePlayerDelegate handlers.
Using BlazeInlinePlayerDelegate with BlazeSwiftUIVideosInlinePlayerView
Here's a simple example showing how to create and pass a BlazeInlinePlayerDelegate to a BlazeSwiftUIVideosInlinePlayerView:
import SwiftUI
import BlazeSDK
struct VideoPlayerView: View {
@State private var isLoading = false
@State private var errorMessage: String?
// Create the delegate
private let playerDelegate = BlazeInlinePlayerDelegate(
onDataLoadStarted: { _ in
// Update loading state
DispatchQueue.main.async {
self.isLoading = true
}
},
onDataLoadComplete: { info in
// Handle load completion
DispatchQueue.main.async {
self.isLoading = false
if case .failure(let error) = info.result {
self.errorMessage = error.localizedDescription
}
}
},
onPlayerDidEnterFullScreen: { _ in
print("Player entered fullscreen mode")
},
onPlayerDidExitFullScreen: { _ in
print("Player exited fullscreen mode")
},
onPlaceholderClicked: { _ in
print("Placeholder thumbnail was tapped")
}
)
var body: some View {
VStack {
// Player view with delegate
BlazeSwiftUIVideosInlinePlayerView(
playerMode: .interactive(interactivePlyerStyle: .base()),
dataSourceType: .labels(.singleLabel("highlights")),
embeddedState: .player(autoPlayOnStart: true),
containerIdentifier: "swiftui-player"
)
.inlinePlayerDelegate(playerDelegate) // Pass the delegate using the modifier
.frame(height: 240)
.cornerRadius(12)
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color.gray.opacity(0.2), lineWidth: 1)
)
// Loading indicator
if isLoading {
ProgressView()
.padding()
}
// Error message
if let errorMessage = errorMessage {
Text("Error: \(errorMessage)")
.foregroundColor(.red)
.padding()
}
}
.padding()
}
}This example demonstrates:
- Creating a
BlazeInlinePlayerDelegatewith handlers for key events - Using the
.inlinePlayerDelegate()modifier to pass the delegate to the player view - Updating SwiftUI state in response to delegate events
- Displaying loading and error states based on delegate callbacks
The delegate allows your SwiftUI view to respond to player events like loading states, errors, and fullscreen transitions, enabling you to build a responsive and user-friendly video experience.
Delegate Handlers
onDataLoadStarted
public var onDataLoadStarted: OnDataLoadStartedHandler?Called when the player begins loading data from the configured data source.
onDataLoadComplete
public var onDataLoadComplete: OnDataLoadCompleteHandler?Called when the player finishes loading data from the configured data source, providing the result and item count.
onPlayerDidAppear
public var onPlayerDidAppear: OnPlayerDidAppearHandler?Called when the player appears on screen for the first time.
onPlayerDidDismiss
public var onPlayerDidDismiss: OnPlayerDidDismissHandler?Called when the player is removed completely from the view hierarchy.
onTriggerCTA
public var onTriggerCTA: OnTriggerCTAHandler?Called when a call-to-action is triggered within the player.
onPlayerDidEnterFullScreen
public var onPlayerDidEnterFullScreen: onPlayerDidEnterFullScreenHandler?Called when the player transitions to full-screen mode.
onPlayerDidExitFullScreen
public var onPlayerDidExitFullScreen: onPlayerDidExitFullScreenHandler?Called when the player exits from full-screen mode.
onPlaceholderClicked
public var onPlaceholderClicked: OnPlaceholderClickedHandler?Called when the user taps on the placeholder image.
Updated about 2 months ago
