BlazeVideosInlinePlayer
The BlazeVideosInlinePlayer class provides a flexible solution for embedding video content within your iOS application. It supports different display modes, seamless transitions between inline and full screen states, and comprehensive event delegation.
Player Modes
There are two distinct player modes available:
- Interactive Mode - A fully interactive inline player with comprehensive overlay controls
- Preview Mode - A minimal overlay player that transitions to full screen on tap
Implementation
Player Initialization
// Create a player with interactive mode
let playerMode = BlazeVideosInlinePlayer.PlayerMode.interactive(
interactivePlyerStyle: .base()
)
// Initialize with a data source
let player = BlazeVideosInlinePlayer(
playerMode: playerMode,
dataSourceType: .labels(.singleLabel("ronaldo")),
containerDelegate: myPlayerDelegate
)
// Prepare videos in advance (optional)
player.prepareVideos()Embedding the Player
// First, embed a placeholder and prepare resources.
player.embedPlaceholder(
in: containerViewController,
containerView: videoContainerView
)
// Or directly embed the player for auto-play experience
player.embedPlayer(
in: containerViewController,
containerView: videoContainerView,
shouldAutoPlayOnStart: true
)Properties
The BlazeVideosInlinePlayer class provides properties to configure and interact with the video player.
containerDelegate
public var containerDelegate = BlazeInlinePlayerDelegate()A delegate that receives notifications about player events, including data loading, player appearance/dismissal, and user interactions. You can set handlers for various events through this delegate.
Methods
init
public init(
playerMode: PlayerMode,
dataSourceType: BlazeDataSourceType,
containerDelegate: BlazeInlinePlayerDelegate? = nil,
containerIdentifier: String = "\(Date().timeIntervalSince1970)",
shouldOrderVideosByReadStatus: Bool = true,
cachePolicyLevel: BlazeCachePolicyLevel? = nil,
adsConfigType: BlazeVideosAdsConfigType = .firstAvailableAdsConfig
)Initializes a new video player with the specified configuration.
Parameters:
- playerMode: Determines the visual and behavioral style of the player (interactive or preview).
- dataSourceType: The data source used to fetch videos (labels, IDs, etc.).
- containerDelegate: Optional delegate to receive player events.
- containerIdentifier: Unique identifier for the player container. Defaults to current timestamp.
- shouldOrderVideosByReadStatus: Whether to prioritize unread videos. Defaults to true.
- cachePolicyLevel: Optional cache policy level for video content.
- adsConfigType: Specifies the ad configuration. Defaults to first available configuration.
prepareVideos
public func prepareVideos()Preloads video content based on the configured data source. Call this method in advance before embedding, to reduce loading time when the player is displayed.
embedPlaceholder
@MainActor
public func embedPlaceholder(
in containerVC: UIViewController,
containerView: UIView
)Embeds a placeholder image in the specified container view. This is useful for showing a preview that users can tap to start playback.
Parameters:
- containerVC: The view controller that will contain the placeholder.
- containerView: The view that will contain the placeholder.
embedPlayer
@MainActor
public func embedPlayer(
in containerVC: UIViewController,
containerView: UIView,
shouldAutoPlayOnStart: Bool
)Embeds the video player in the specified container view. This method is used to display the player with controls.
Parameters:
- containerVC: The view controller that will contain the player.
- containerView: The view that will contain the player.
- shouldAutoPlayOnStart: Whether the video should automatically play when loaded.
resumePlayer
@MainActor
public func resumePlayer()Resumes playback of the currently paused video. This method has no effect if the player is not embedded.
pausePlayer
@MainActor
public func pausePlayer()Pauses the currently playing video. This method has no effect if the player is not embedded.
enterFullScreen
@MainActor
public func enterFullScreen()Transitions the player to fullscreen mode. This method only works after the player is embedded.
resetToPlaceholder
@MainActor
public func resetToPlaceholder()Resets the player to its placeholder state while keeping references to the container view. This is useful for reverting to a preview state after playback.
remove
@MainActor
public func remove()Removes the player and its placeholder from the container view hierarchy while maintaining resources. This is called automatically when an instance of BlazeVideosInlinePlayer is released.
blockPlayerInteraction
@MainActor
public func blockPlayerInteraction()Blocks user interaction with the current video player instance. This prevents user input while maintaining playback functionality.
unblockPlayerInteraction
@MainActor
public func unblockPlayerInteraction()Unblocks user interaction with the current video player instance. This restores normal user interaction capabilities.
Updated 16 days ago
