AtomicPlayer
Introduction
AtomicPlayer manages video stream playback for low-latency live streaming and CDN streams. The render view is bound at runtime via setView; the video frames will be rendered into the given AtomicLiveView container. This binding is decoupled from the view's window-attachment timing: it is safe to call setView before the view is attached to a window (e.g. inside UICollectionView cells or RecyclerView), the binding will be completed automatically once the view is ready. Key Features:Stream pulling and playback (
startPlay / stopPlay).Render view binding and rotation mode control (
setView / setRenderRotation).Channel join and leave (
joinChannel / leaveChannel).Playback control (
switchStream).SEI message receiving (
enableReceiveSeiMessage).Playback state and statistics (
state real-time state, PlayerStatistics statistics).Event callbacks (SEI data, errors, live ended, kicked out, etc. via
playerEvent on Swift or addListener on Kotlin).Features
PlayerState: Playback state, including playback lifecycle state and statistics.
PlayerEvent: Player event callbacks, including SEI receiving, playback errors, live ended, kicked out, and other event types.
Subscribable Data
PlayerState fields are described below:
Property | Type | Description |
playbackStatus | Playback status. Reflects the current playback lifecycle. | |
statistics | Playback runtime statistics, delivered periodically by the SDK. | |
totalViewerCount | Int | Total viewer count. |
API List
Function | Description |
Player event publisher. | |
Set the render view. | |
Set render rotation angle. | |
Capture the current video frame. | |
Start playing the remote stream specified by URL. | |
Stop playback. | |
Seamlessly switch to a new stream URL. | |
Set playback volume. | |
Join channel. | |
Leave channel. | |
Enable or disable receiving SEI messages. | |
Enable advanced features by key-value pair. |
Observing State and Events
playerEvent
Player event publisher.
View Management
setView
Set the render view. The video frames will be rendered into the given
AtomicLiveView container. This binding is decoupled from the view's window-attachment timing: it is safe to call this before the view is attached to a window (e.g. inside UICollectionView cells or RecyclerView), the binding will be completed automatically once the view is ready.public func setView(_ view: AtomicLiveView) { impl.setView(view) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
view | Render view container. |
setRenderRotation
Set render rotation angle.
public func setRenderRotation(_ rotation: PlayerRenderRotation) { impl.setRenderRotation(rotation) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
rotation | Render rotation angle. |
snapshot
Capture the current video frame.
public func snapshot(completion: ((UIImage?) -> Void)? = nil) { impl.snapshot(completion: completion) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
completion | ((UIImage?) -> Void)? | Snapshot result callback. The image is nil if the snapshot fails. |
Playback Control
startPlay
Start playing the remote stream specified by URL. Calling this method on an already-playing instance will stop the previous stream and play the new one.
public func startPlay(url: String) { impl.startPlay(url: url) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
url | String | Stream URL. |
stopPlay
Stop playback.
public func stopPlay() { impl.stopPlay() }
Version
Supported since version 3.5.
switchStream
Seamlessly switch to a new stream URL without tearing down the current render view. Suitable for quality switching (such as 720p → 1080p) and CDN line failover.
public func switchStream(url: String, completion: CompletionClosure? = nil) { impl.switchStream(url: url, completion: completion) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
url | String | New stream URL. |
completion | Completion callback (success/failure status). |
setVolume
Set playback volume.
public func setVolume(_ volume: Int) { impl.setVolume(volume) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
volume | Int | Volume level, with a value range from 0 to 100; values outside the range will be clamped. |
Channel Management
joinChannel
Join channel.
public func joinChannel(liveID: String, completion: CompletionClosure?) { impl.joinChannel(liveID: liveID, completion: completion) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
liveID | String | Live ID. |
completion | Completion callback. |
leaveChannel
Leave channel.
public func leaveChannel() { impl.leaveChannel() }
Version
Supported since version 3.5.
SEI Messages
enableReceiveSeiMessage
Enable or disable receiving SEI messages. When enabled, SEI data embedded in the video stream will be delivered via the
PlayerEvent.seiReceived event.public func enableReceiveSeiMessage(enable: Bool, payloadType: Int) { impl.enableReceiveSeiMessage(enable: enable, payloadType: payloadType) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
enable | Bool | Whether to enable SEI message receiving. |
payloadType | Int | SEI payload type to filter. Common values: 243 (custom layout), 100 (volume layout), 245 (ASR message). |
Advanced Features
enableAdvancedFeature
Enable an advanced feature by key-value pair. Supported keys depend on the underlying native player capability and may evolve over versions.
public func enableAdvancedFeature(key: String, value: Any) { impl.enableAdvancedFeature(key: key, value: value) }
Version
Supported since version 3.5.
Parameters
Parameter | Type | Description |
key | String | Feature key. |
value | Any | Feature value, type depends on the specific key. |
Data Structures
PlayerCode
Atomic player error code enumeration, used to report the result of player operations and runtime errors.
Enum Value | Value | Description |
OK | 0 | No error, operation succeeded. |
ERROR_INVALID_PARAMETER | -1001 | Invalid parameter. |
PlayerPlaybackStatus
Status of the player, reflecting the current playback lifecycle. State machine (typical transitions):
startPlayIDLE ──────────────────▶ LOADING▲ ││ play succeededstopPlay │connection lost ││ ▼│◀─────────────────────PLAYING ◀────────────────┐│ │ ││ │ ││ buffering recover succeeded│ │ ││ ▼ │└──────────────────────LOADING ─────────────────┘
Note:
IDLE is the initial state; it is also returned to after calling stopPlay. The buffering / auto-recovery process reuses LOADING, without distinguishing "first loading" from "re-buffering".Enum Value | Value | Description |
IDLE | 0 | Idle. Initial state, or playback stopped / connection lost. |
LOADING | 1 | Loading. Establishing the connection or buffering data; the video has not started or is temporarily stalled. |
PLAYING | 2 | Playing. The link is normal and the video is playing smoothly. |
PlayerRenderRotation
Render rotation angle of the video.
Enum Value | Value | Description |
ROTATION_0 | 0 | No rotation. |
ROTATION_90 | 1 | Rotated 90 degrees clockwise. |
ROTATION_180 | 2 | Rotated 180 degrees clockwise. |
ROTATION_270 | 3 | Rotated 270 degrees clockwise. |
PlayerListener
Player event listener, used to receive one-shot events such as SEI data, playback errors, live ended, kicked out, etc. Register/remove listeners via
addListener / removeListener.PlayerStatistics
Atomic player runtime statistics, containing real-time runtime metrics of an active player.
Property | Type | Description |
videoWidth | Int | Video width in pixels. |
videoHeight | Int | Video height in pixels. |
videoFps | Int | Video frame rate in fps. |
videoBitrate | Int | Video bitrate in bps. |
audioBitrate | Int | Audio bitrate in bps. |
PlayerState
Atomic player reactive state. Carries the state of AtomicPlayer. You can read the current value or observe changes via
state.Property | Type | Description |
playbackStatus | Playback status. Reflects the current playback lifecycle. | |
statistics | Playback runtime statistics, delivered periodically by the SDK. | |
totalViewerCount | Int | Total viewer count. |
