Using with BBNativePlayerKit
By default, the channel plays video in the WebView using the standard web player. For better performance and platform integration, you can use BBNativePlayerKit to play video with AVPlayer natively.
Setup
- Add
BBNativePlayerKitto your project (via CocoaPods or as a local xcframework) - Enable native player mode in the channel options:
let options = BBChannelOptions(nativePlayerMode: true)
When nativePlayerMode is enabled, the channel will not create a web player. Instead, it fires onMediaPlay events that your app handles by creating a native player.
Handling Media Play
import BBChannelSwiftUI
import BBNativePlayerKit
struct ChannelScreen: View {
@StateObject private var viewModel = BBChannelViewModel()
@State private var activePlayer: BBNativePlayer?
var body: some View {
ZStack {
BBChannelView(
channelUrl: "https://demo.bbvms.com/ch/1152.json",
options: BBChannelOptions(nativePlayerMode: true),
viewModel: viewModel,
callbacks: BBChannelCallbacks(
onMediaPlay: { media in
handleMediaPlay(media)
},
onMediaEnd: { _ in
activePlayer = nil
}
)
)
if let player = activePlayer {
NativePlayerView(player: player)
}
}
}
private func handleMediaPlay(_ media: BBMediaInfo) {
guard let jsonUrl = media.jsonUrl else { return }
let player = BBNativePlayer()
player.load(jsonUrl: jsonUrl)
if media.isInlinePlayer {
// Inline player — position over the WebView player area
player.play()
} else {
// Modal/fullscreen player
player.enterFullscreen()
player.play()
}
activePlayer = player
}
}
Auto-Advance with Context
When nativePlayerMode is enabled and the channel is configured with playlists, the onMediaPlay event includes playlist context for auto-advance:
onMediaPlay: { media in
if let context = media.context,
let clipListId = media.clipListId,
let index = media.index {
print("Playing clip \(index) of playlist \(clipListId)")
// Use context to load the next clip when playback ends
}
}
The context dictionary contains the playlist data needed to advance to the next clip. Pass it to your native player's playlist handler for seamless auto-advance behavior.
Architecture
The native player integration uses the same WebView bridge as all other SDK features. When nativePlayerMode is true:
- Channel JS detects native mode and skips iframe player creation
- A
mediaPlayevent is posted to the WebView bridge - The SDK deserializes it into a
BBMediaInfoand firesonMediaPlay - Your app creates a native AVPlayer overlay
See Architecture for the full bridge design.