Skip to main content

BBPlayerState

class BBPlayerState

Reactive state holder that bridges BBNativePlayerViewDelegate callbacks to SwiftUI state.

Observe any property in a SwiftUI view to trigger automatic updates (per-property tracking via @Observable). Use the imperative control methods (play(), pause(), seek(to:), etc.) to control the player.

Create with @State private var playerState = BBPlayerState().

Important: Call destroy() from .onDisappear to ensure timely cleanup of SDK resources, or use the convenience BBNativePlayer/init(jsonUrl:options:) initializer for automatic lifecycle management.

Functions​

autoPlayNextCancel​

func autoPlayNextCancel()

Cancel auto-play next.

collapse​

func collapse()

Collapse the player (outstream).

destroy​

func destroy()

Destroy the player and release resources.

endCastSession​

func endCastSession()

End the current Cast session and stop playback on the Cast device.

enterFullScreen​

func enterFullScreen()

Enter fullscreen mode.

exitFullScreen​

func exitFullScreen()

Exit fullscreen mode.

expand​

func expand()

Expand the player (outstream).

loadClip​

func loadClip(id clipId: String, autoPlay: Bool = true, seekTo: Double? = nil, context: [String: Any]? = nil)

Load a clip by ID.

loadClipList​

func loadClipList(id clipListId: String, autoPlay: Bool = true)

Load a clip list by ID.

loadProject​

func loadProject(id projectId: String, autoPlay: Bool = true)

Load a project by ID.

pause​

func pause()

Pause playback.

play​

func play()

Start or resume playback.

resumeCastSession​

func resumeCastSession()

Detect and resume an existing Cast session.

seek​

func seek(to seconds: Double)

Seek to the given absolute position in seconds.

seekRelative​

func seekRelative(_ offsetInSeconds: Double)

Seek relative to the current position (e.g. +10.0 or -10.0 seconds).

setCastMode​

func setCastMode(_ mode: String?)

Set Cast routing mode. "auto" for native channel SDKs.

setMuted​

func setMuted(_ muted: Bool)

Set the muted state.

setVolume​

func setVolume(_ volume: Double)

Set the playback volume (0.0 to 1.0).

showCastPicker​

func showCastPicker()

Show the Google Cast device picker.

The Google Cast SDK is initialized automatically on first use via the SDK's ChromeCastHelper.

unload​

func unload()

Unload current media without destroying the player (for reuse).

Properties​

currentTime​

internal(set) var currentTime: Double

Current playback position in seconds. Updated on seek, clip load, and playback end.

isCasting​

var isCasting: Bool

Whether the player is currently casting to a Chromecast device.

isMuted​

internal(set) var isMuted: Bool

Whether the player is muted.

Note: This value is only updated when setMuted(_:) is called from Swift code. The underlying SDK does not provide a mute-change callback, so changes made via the player's own skin controls will not be reflected here.