Skip to main content

Native Player Integration

The BB Channel SwiftUI SDK uses BBNativePlayerKit for native video playback. This provides smooth, hardware-accelerated playback with full Chromecast support.

BBChannelWithPlayerView

BBChannelWithPlayerView is the recommended way to integrate channels with native video. It provides:

  • Native inline player on detail pages
  • Back arrow navigation header
  • Player reuse across page transitions (no re-creation overhead)
  • Playlist auto-advance
  • Modal player for main page video playback
  • Chromecast support
import SwiftUI
import BBChannelSwiftUI
import BBNativePlayerKit_SwiftUI

struct ChannelScreen: View {
@StateObject private var playerVM = BBChannelWithPlayerViewModel()

var body: some View {
BBChannelWithPlayerView(
channelUrl: "https://yourdomain.bbvms.com/ch/123.json",
viewModel: playerVM,
callbacks: BBChannelCallbacks(
onReady: { print("Channel loaded") }
)
)
}
}

Installation

Add both packages via Swift Package Manager:

.product(name: "BBChannelSwiftUI", package: "channel-sdks"),
.product(name: "BBNativePlayerKit-SwiftUI", package: "bbnativeplayerkit-swift"),

Info.plist Configuration (Required)

Add the following keys to your Info.plist for Chromecast device discovery:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app uses Bluetooth for casting video to external devices.</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app uses Bluetooth for casting video to external devices.</string>
<key>NSBonjourServices</key>
<array>
<string>_googlecast._tcp</string>
<string>_1F61A3A5._googlecast._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>This app uses the local network to discover Cast devices.</string>
warning

These entries are required. Without them, Cast device discovery causes excessive CPU usage and battery drain.

Configuration

PropertyTypeDefaultDescription
showBackArrowBooltrueShow back arrow header above player on detail pages
playerAspectRatioCGFloat16/9Aspect ratio for the inline player

Custom Player Handling (Advanced)

For full control over the player lifecycle, use BBChannelView directly and handle onMediaPlay events yourself:

BBChannelView(
channelUrl: "https://yourdomain.bbvms.com/ch/123.json",
viewModel: viewModel,
callbacks: BBChannelCallbacks(
onMediaPlay: { media in
// Create and manage native player manually
}
)
)

Example App

A full working example is available at github.com/bluebillywig/channel-examples/swiftui.