API reference
AliPlayerKit provides a rich set of APIs for controlling player behavior. This document details the main APIs for AliPlayerKit on iOS.
AliPlayerKit includes detailed code comments for all core APIs, such as classes and methods. In Xcode, you can view these comments with Quick Help (Option + Click) to accelerate development. This also makes the APIs more friendly to AI programming tools.
Core class overview
Class name | Type | Responsibility | Lifecycle |
| Global entry point | SDK initialization, global configuration, factory/preloader management | App lifecycle |
| View container | Player view management, slot system host | Same as UIView |
| Playback controller | Playback control, state management, strategy coordination | Manually released by `destroy` |
| Data model | Encapsulates video source and playback parameters | Value object, no independent lifecycle |
| State store | Read-only access to the player's current state | Follows the Controller |
| View state | Read-only access to UI layer state (fullscreen, control bar visibility) | Follows AliPlayerView |
| Slot manager | Slot registration, visibility control, element-level management | Follows AliPlayerView |
| Strategy manager | Strategy registration, start, stop, and reset | Follows the Controller |
| Strategy registry | Global default strategy factory management (singleton) | App lifecycle |
| Log center | Log output and observer management (singleton) | App lifecycle |
| Localization management | Multilingual support and Provider injection (singleton) | App lifecycle |
AliPlayerKit (Global APIs)
AliPlayerKit is a global settings class for SDK initialization and configuration. You cannot instantiate this class. All its methods are class methods.
Initialization methods
Method | Parameter | Return value | Description |
| - | void | Initializes the SDK. `dispatch_once` ensures idempotency. Call this method when the app starts. |
| - | BOOL | Checks if the SDK is initialized. |
| OnGlobalInitBlock block | void | Sets a custom configuration callback after global initialization is complete. Call this method before `setup`. |
Status query and version information
Method | Parameter | Return value | Description |
| - | NSString * | Gets the PlayerKit version number. |
| - | NSString * | Gets the underlying AliPlayer SDK version number. |
Debug configurations
Method | Parameter | Return value | Description |
| BOOL enabled | void | Enables or disables debug mode. |
| - | BOOL | Checks if debug mode is enabled. |
| BOOL enabled | void | Enables or disables the log panel. This feature is for debugging only. |
| - | BOOL | Checks if the log panel is enabled. |
Log configurations
Method | Parameter | Return value | Description |
| LogLevel level | void | Sets the log level. Logs below this level are ignored. The default level is Info. |
| - | LogLevel | Gets the current log level. |
| BOOL enable | void | Enables or disables console log output. |
| - | BOOL | Checks if console log output is enabled. |
Player factory
Method | Parameter | Description |
| id<PlayerFactory> factory | Sets a custom player factory. Pass `nil` to restore the default factory. |
| - | Gets the current player factory. |
Preloading
Method | Parameter | Description |
| id<PlayerPreloader> preloader | Sets a custom preloader. Pass `nil` to restore the default preloader. |
| - | Gets the current preloader. |
Cache management
Method | Description |
| Clears the local media cache of the player. Call this method after `setup`. |
Internationalization
Method | Parameter | Description |
| NSString * languageCode | Manually specifies the language. Supported languages are `zh-Hans` and `en`. |
| id<LocaleProvider> provider | Injects a custom localization provider. This has the highest priority. |
| - | Resets the language to follow the system language. |
| - | Gets the current language code. |
AliPlayerView (View APIs)
AliPlayerView is the player's view container. It manages controller binding and the slot system. The rendering view is created and managed by the internal PlayerSurfaceSlot.
Properties
Property | Type | Description |
controller | AliPlayerController * | The associated player controller. |
viewState | PlayerViewState * | The UI state that is retained across videos, such as fullscreen and control bar visibility. |
slotManager | SlotManager * | The slot manager. You can pre-configure it before attaching. |
fullscreenTransition | id<FullscreenTransition> | The implementation of the fullscreen transition animation. By default, an independent window rotation solution is used. |
onBackPressed | void (^)(void) | The callback for the back button event. |
The `onBackPressed` callback is triggered in non-fullscreen mode. In fullscreen mode, the player automatically handles the back operation by exiting fullscreen. If this callback is not set, the player attempts a default navigation behavior, such as `pop` or `dismiss`, through the responder chain.
Controller binding
Method | Parameter | Description |
| AliPlayerController * controller | Binds the controller and activates the slot system. |
| - | Detaches the controller without destroying it. |
When to call:
attach:: The component is attached after the controller callsconfigure:. The slot system is then automatically built based on the slotManager configuration.detach: Call this method when the view is about to be destroyed or when you need to bind a different controller.
AliPlayerController (Controller APIs)
AliPlayerController is the playback controller. It serves as a unified entry point for playback operations and encapsulates the logic for player creation, configuration, and control.
Properties
Property | Type | Description |
playerModel | AliPlayerModel * | The current playback configuration model. |
playerState | PlayerState | The current player state. |
currentPosition | NSInteger | The current playback position in milliseconds. |
duration | NSInteger | The total duration of the video in milliseconds. |
stateStore | PlayerStateStore * | The state store. |
strategyManager | StrategyManager * | The strategy manager. |
lifecycleStrategy | id<PlayerLifecycleStrategy> | The current lifecycle strategy. |
autoLifecycleManagement | BOOL | Specifies whether to automatically manage the foreground and background lifecycle. Default: YES. |
controlsVisibilityLocked | BOOL | The lock flag for control bar visibility. |
When controlsVisibilityLocked is set to YES, the setControlsVisible:NO request is ignored, and the control bar remains visible. This is used for interactive scenarios, such as dragging the progress bar, where the control bar must always be displayed.
Constructors
Method | Parameter | Description |
| - | Creates a controller with the default lifecycle strategy. |
|
| Creates a controller with a custom lifecycle strategy. |
Configuration and playback control
Method | Parameter | Description |
| AliPlayerModel * model | Configures the player and prepares for playback. |
| - | Starts or resumes playback. |
| - | Pauses playback. |
| - | Toggles between play and pause. |
| - | Restarts playback from the beginning. |
| - | Stops playback. |
| NSInteger position (milliseconds) | Seeks to a specific position. |
| float rate | Sets the playback speed. 1.0 is normal speed. |
| BOOL loop | Sets whether to loop playback. |
| BOOL muted | Sets whether to mute the audio. |
| MirrorMode mirrorMode | Sets the mirror mode. |
| ScaleMode scaleMode | Sets the scaling mode. |
| RotateMode rotateMode | Sets the rotation angle. |
| TrackQuality * quality | Switches the video quality. |
| - | Takes a snapshot of the current video frame. |
UI control
Method | Parameter | Return value | Description |
|
|
| Sets the visibility of the control bar. |
|
|
| Sets fullscreen mode with animation. |
|
|
| Sets fullscreen mode with optional animation. |
Lifecycle methods
Method | Parameter | Return value | Description |
| - |
| Resumes playback. Call this when returning from the background. |
| - |
| Pauses playback. Call this when entering the background. |
| - |
| Destroys the player and releases all resources. |
Notification delegates
Method | Parameter | Return value | Description |
|
|
| Adds a notification delegate. It is held by a weak reference. |
|
|
| Removes a notification delegate. |
AliPlayerModel (Model APIs)
AliPlayerModel is the player configuration model. It encapsulates all the configuration information required for playback.
Properties
Property | Type | Default value | Description |
|
| - | The video data source. This is required. |
|
|
| The playback scenario type. |
|
|
| The thumbnail URL. |
|
|
| The video title. |
|
|
| Specifies whether to enable autoplay. |
|
|
| The tracking identifier for playback quality monitoring. |
|
|
| The start position in milliseconds. |
|
|
| Specifies whether to enable hardware decoding. |
|
|
| Specifies whether to allow the screen to sleep. |
|
|
| Specifies whether to disable screenshots and screen recording. |
|
|
| The instance-level custom configuration callback. |
Creation methods
Method | Parameter | Return value | Description |
|
|
| Creates a model from a video source. This is the designated initializer. |
Notification system
AliPlayerKit uses a Dispatcher + Delegate pattern for event communication between components. Each AliPlayerController has an independent Dispatcher instance, which prevents events from different player instances from interfering with each other. All callbacks are dispatched on the main thread.
PlayerNotificationDelegate (Player notification delegate)
A protocol for player state change callbacks. All methods are @optional.
Playback state
Method | Parameter | Description |
|
| The player state changes. |
|
| The player is prepared and ready for playback. |
| - | The first frame is rendered. |
| - | Playback is complete. |
Playback progress
Method | Parameter | Description |
| position, duration, bufferedPosition (milliseconds) | Reports the playback progress at regular intervals. |
Errors and snapshots
Method | Parameter | Description |
|
| A playback error occurred. |
|
| A snapshot is taken. |
Video information
Method | Parameter | Description |
|
| The video dimensions change. |
UI state
Method | Parameter | Description |
|
| The fullscreen state changes. |
|
| The visibility of the control bar changes. |
Loading state
Method | Parameter | Description |
| - | Buffering starts. |
| - | Buffering ends. |
|
| The buffering progress is updated. |
Display mode
Method | Parameter | Description |
|
| The mirror mode changes. |
|
| The scaling mode changes. |
|
| The rotation mode changes. |
Track
Method | Parameter | Description |
|
| Information about available tracks is ready. |
|
| The track is switched. |
GestureNotificationDelegate (Gesture notification delegate)
A protocol for gesture interaction event callbacks. All methods are @optional. Events are multicast by GestureNotificationDispatcher.
Single tap
Method | Parameter | Description |
| - | A single tap gesture is triggered. This is typically used to toggle the visibility of the control bar. |
Long press (playback speed)
Method | Parameter | Description |
| - | A long press begins. This activates fast-forward playback. |
| - | A long press ends. This restores normal playback speed. |
Brightness (left vertical drag)
Method | Parameter | Description |
|
| The brightness is being adjusted. |
| - | The brightness adjustment ends. |
Volume (right vertical drag)
Method | Parameter | Description |
|
| The volume is being adjusted. |
| - | The volume adjustment ends. |
SlotActionNotificationDelegate (Slot action notification delegate)
A notification protocol for action events between slots. It is used to decouple direct method calls between slots. All methods are @optional and are dispatched asynchronously to the main thread.
Method | Parameter | Description |
| - | Requests to toggle the visibility of the settings menu. This is usually triggered by `TopBarSlot`. |
| - | Requests to show the playback speed selection panel. This is usually triggered by `BottomBarSlot`. |
| - | Requests to show the video quality selection panel. This is usually triggered by `BottomBarSlot`. |
Player protocols
AliPlayerKit defines the core capabilities and behavioral constraints of the player through protocols.
MediaPlayer (Player protocol)
This protocol defines the core operation interface for the player. You can create an instance using PlayerFactory.
Properties
Property | Type | Description |
| NSString * | The unique identifier of the player. |
| PlayerState | The current playback state. |
| NSInteger | The current position in milliseconds. |
| NSInteger | The total duration in milliseconds. |
| float | The current playback speed. |
| BOOL | Specifies whether to loop playback. |
| BOOL | Specifies whether the audio is muted. |
| MirrorMode | The current mirror mode. |
| ScaleMode | The current scaling mode. |
| RotateMode | The current rotation angle. |
| PlayerStateStore * | The state store. |
Playback control
Method | Parameter | Description |
|
| Sets the video data source. |
| - | Asynchronously prepares player resources. |
| - | Starts playback. |
| - | Pauses playback. |
| - | Toggles between play and pause. |
| - | Restarts playback from the beginning. |
|
| Seeks to a specific position. |
| - | Stop. |
| - | Destroys the player and releases resources. |
Playback settings
Method | Parameter | Description |
|
| Sets the playback speed (0.5 to 2.0). |
|
| Sets loop playback. |
|
| Mutes the audio. |
|
| Sets the mirror mode. |
|
| Sets the scaling mode. |
|
| Sets the rotation angle. |
|
| Switches the video quality. |
| - | Takes a snapshot of the current frame. |
PlayerLifecycleStrategy (Lifecycle strategy protocol)
This protocol defines the acquisition and recycling behavior of player instances.
Methods
Method | Parameter | Return value | Description |
|
|
| Injects the player factory. This must be called first. |
| - |
| Gets a player instance. |
| player, |
| Recycles a player instance. |
| - |
| Releases all cached instances. |
|
|
| Preloads a specified number of instances into the pool. |
|
|
| Gets a player by ID. This is specific to the IdScoped strategy. |
| player, uniqueId, force |
| Recycles a player by ID. This is specific to the IdScoped strategy. |
Built-in strategy implementations
Strategy class | Behavior | Scenarios |
| Creates a new instance each time and destroys it upon recycling. | Normal video playback. |
| Global unique instance ( | List playback, memory-sensitive scenarios. |
| LIFO reuse pool. | Short video lists. |
| ID binding + LRU eviction. | Video preloading. |
FullscreenTransition (Fullscreen transition protocol)
This protocol defines the transition behavior for entering and exiting fullscreen mode.
Method / Property | Parameter | Description |
| playerView, animated, completion | Enters fullscreen. |
| playerView, animated, completion | Exits fullscreen. |
| - | Specifies whether the player is in fullscreen mode. |
The default implementation DefaultFullscreenTransition uses an independent Window rotation solution. You can inject a custom implementation via playerView.fullscreenTransition.
Slot system
The slot system provides a composable and replaceable UI layer management mechanism.
SlotProtocol (Slot protocol)
You can define the slot lifecycle callback.
Method | Parameter | Description |
|
| The slot is attached to the host. |
| - | The slot is detached from the host. |
|
| Playback data is bound. |
| - | Playback data is unbound. |
BaseSlot (Base slot class)
The abstract base class for all built-in slots (a UIView subclass) implements the SlotProtocol protocol and provides common capabilities.
Properties
Property | Type | Description |
| id<SlotHost> | The host to which the slot is attached. |
| SlotType | The slot type identifier. It is injected by SlotHostLayout. |
| SlotSafeAreaEdge | The safe area edges to avoid. Default: All. |
| BOOL | The switch for deferred content creation. |
| BOOL | Specifies whether the content is ready. |
| BOOL | The switch for touch passthrough. Default: YES. |
Methods
Method | Type | Description |
| - | Subclasses override this method to add custom UI elements. |
| - | Shows or hides the slot. |
|
| Shows or hides the slot with an animation. |
| - | Indicates whether it is currently visible. |
| - | Correctly removes the slot through the host. |
| - | Subclasses override this method to declare the bitmask of default visible elements. |
|
| Queries the final visibility of a specific element. |
| - | Safely reads the current scene type. |
| - | Ensures that deferred content is ready. |
SlotManager (Slot manager)
The SlotManager is the unified management entry point for the slot system. You can retrieve it using AliPlayerView.slotManager.
Registration methods
Method | Parameter | Description |
| type, | Registers or replaces a slot provider. |
|
| Unregisters a slot provider. |
|
| Check if it is registered. |
|
| Registers a custom slot. |
|
| Unregisters a custom slot. |
Slot visibility
Method | Parameter | Description |
|
| Hides an entire slot. |
|
| Shows a hidden slot. |
|
| Checks if a slot is hidden. |
Element-level visibility
Method | Parameter | Description |
|
| Hides specific elements within a slot using a bitmask. |
|
| Shows previously hidden elements. |
|
| Replaces the hidden element mask. This overwrites the existing mask. |
|
| Sets all hidden elements in a batch. |
| - | Clears all element visibility configurations. |
Runtime access
Method | Parameter | Return value | Description |
|
|
| Gets the attached slot view. |
| - |
| Rebuilds all slots. |
| - |
| Resets to the initial state. |
SlotType (Slot type constants)
Constant | Value | Description |
| 10 | Player rendering view layer (bottommost). |
| 20 | Gesture recognition and control layer. |
| 30 | Landscape hint layer. |
| 40 | Video thumbnail layer. |
| 50 | Center display layer (playback speed, brightness, volume). |
| 60 | Playback state indicator layer (loading, error, complete). |
| 70 | Log panel layer. |
| 80 | Top navigation bar layer. |
| 90 | Bottom control bar layer. |
| 100 | Settings menu layer. |
| 110 | Option panel layer (playback speed, quality). |
CustomSlotType (Custom slot type)
This is used to insert custom slots between built-in slots. The built-in SlotType enumeration values are arranged at intervals of 10 (10, 20, ..., 110), and CustomSlotType uses the order field to specify the insertion position.
Property / Method | Description |
| A unique identifier used for registration, lookup, and equality checks. |
| The sort value that determines the slot's position on the Z-axis. A smaller value means it is placed lower. |
| Creates a custom slot type instance. |
// Insert a custom slot between TopBar (80) and BottomBar (90)
CustomSlotType *type = [CustomSlotType typeWithKey:@"myCustomSlot" order:85];
[playerView.slotManager registerCustomSlotType:type provider:^UIView<SlotProtocol> *(UIView *parentView) {
return [[MyCustomSlotView alloc] initWithFrame:parentView.bounds];
}];SlotElements (Slot element bitmasks)
You can use the hideElements:forSlot: and showElements:forSlot: methods of SlotManager to implement fine-grained visibility control for individual UI elements in a slot.
Top Bar Element (TopBarElement)
Constant | Bit | Description |
| 1 << 0 | Back button. |
| 1 << 1 | Title text. |
| 1 << 2 | Download button. |
| 1 << 3 | Snapshot button. |
| 1 << 4 | Settings button. |
BottomBarElement (Bottom bar elements)
Constant | Bit | Description |
| 1 << 0 | Play/Pause button. |
| 1 << 1 | Progress bar. |
| 1 << 2 | Refresh button. |
| 1 << 3 | Playback speed button. Visible in landscape layout only. |
SettingMenuElement (Settings menu elements)
Constant | Bit | Description |
| 1 << 0 | Playback speed option. |
| 1 << 1 | Quality information. |
| 1 << 2 | Loop playback. |
| 1 << 3 | Mute. |
| 1 << 4 | Mirror mode. |
| 1 << 5 | Rotation mode. |
| 1 << 6 | Scaling mode. |
| 1 << 7 | Caption. |
CenterDisplayElement (Center display layer elements)
Constant | Bit | Description |
| 1 << 0 | Volume indicator. |
| 1 << 1 | Brightness indicator. |
| 1 << 2 | Playback speed indicator. |
GestureElement (Gesture control elements)
These constants control the enabling and disabling of gesture interactions, not the visibility of UI elements. When a gesture bit is set to hidden, the corresponding gesture is disabled.
Constant | Bit | Description |
| 1 << 0 | Single tap gesture. |
| 1 << 1 | Double-tap gesture. |
| 1 << 2 | Long press gesture. |
| 1 << 3 | Horizontal drag (progress). |
| 1 << 4 | Left vertical drag (brightness). |
| 1 << 5 | Right vertical drag (volume). |
PlayStateElement (Playback state layer elements)
Constant | Bit | Description |
| 1 << 0 | Error message. |
| 1 << 1 | Loading message. |
State store
PlayerStateStore
PlayerStateStore holds a read-only snapshot of the current playback state. You can retrieve it through AliPlayerController.stateStore.
Property | Type | Default value | Description |
|
|
| The current playback state. |
|
| 0 | The total duration in milliseconds. |
|
| 0 | The current position in milliseconds. |
|
| 0 | The buffered position in milliseconds. |
|
| 1.0 | The current playback speed. |
|
| NO | Specifies whether to loop playback. |
|
| NO | Specifies whether the audio is muted. |
|
|
| The mirror mode. |
|
|
| The scaling mode. |
|
|
| The rotation angle. |
|
| 0 | The original width of the video. |
|
| 0 | The original height of the video. |
|
| nil | The list of available video qualities. |
|
| nil | The currently selected video quality. |
PlayerViewState
PlayerViewState holds persistent state related to the UI layer. You can retrieve it through AliPlayerView.viewState. This state is retained across video switches, and state updates include automatic deduplication.
Property / Method | Type | Default value | Description |
|
|
| Specifies whether the player is in fullscreen mode. |
|
|
| Specifies whether the control bar is visible. |
| - | - | Resets all states to their default values. |
|
| - | Updates the fullscreen state. |
|
| - | Updates the visibility of the control bar. |
Video source
VideoSource (Video source model)
Property | Type | Description |
|
| The video source type. |
|
| The unique identifier. Returns `vid` for VidAuth/VidSts, and `url` for URL. |
|
| The video URL. Valid for the URL type. |
|
| The video ID. Valid for VidAuth/VidSts. |
|
| The playback credential. Valid for VidAuth. |
|
| The STS AccessKeyId. |
|
| The STS AccessKeySecret. |
|
| The STS SecurityToken. |
|
| The region ID. |
Factory methods
Method | Parameter | Return value | Description |
| vid, playAuth |
| Creates a VidAuth video source. This is recommended. |
| vid, keyId, secret, token, region |
| Creates a VidSts video source. |
| url |
| Creates a URL video source. |
| - |
| Validates the configuration. |
VideoSourceType (Video source type)
Constant | Value | Description |
| 0 | VID + PlayAuth playback credential. This is recommended. |
| 1 | VID + STS temporary credential. |
| 2 | Direct URL playback. |
Strategy system
The strategy system provides a pluggable mechanism for extending playback behavior. Strategy names must be globally unique.
StrategyProtocol (Strategy protocol)
This protocol defines the lifecycle contract for a strategy. Strategy names must be globally unique.
Method | Parameter | Description |
| - | The unique identifier name of the strategy. |
|
| The strategy starts and binds to the player context. |
| - | The strategy stops and unbinds from the context. |
|
| The strategy is reset. This is called when the video source is switched. |
StrategyContext (Strategy context)
The read-only player environment context is provided to the strategy and is created and passed in by StrategyManager when the strategy starts.
Property | Type | Description |
|
| The associated player controller. |
|
| The current playback configuration model. |
|
| The player state store. |
This object is no longer valid after strategyDidStop, and you should not continue to use it.
BaseStrategy (Base strategy class)
An abstract base class for strategies that implements StrategyProtocol and PlayerNotificationDelegate to automatically handle the subscription and unsubscription of player events.
Property / Method | Description |
| The current strategy context. It is valid only between `start` and `stop`. |
| A hook method for subclasses to reset their internal state, such as clearing counters or timers. |
Lifecycle flow: strategyDidStart: → Save context → Register notification agent → strategyDidReset: → Update context → Call resetInternalState → strategyDidStop → Unregister notification agent → Clear context.
Child classes must override the strategyName method. If you override strategyDidStart:, strategyDidStop, or strategyDidReset:, you must call super.
StrategyManager (Strategy manager)
Each AliPlayerController has a StrategyManager instance. Strategies are executed in the order of registration, and the lifecycle calls for each strategy are isolated using @try/@catch.
Methods
Method | Parameter | Description |
|
| Registers a strategy. If a strategy with the same name exists, it is stopped and replaced. |
|
| Unregisters a strategy by name. |
|
| Finds a strategy by name. |
| controller, playerModel | Starts all registered strategies. |
|
| Resets all strategies. This is used when the video source is switched. |
| - | Stops all strategies. |
| - | Stops and removes all strategies. |
Properties
Property | Type | Description |
|
| The number of currently registered strategies. |
|
| Indicates whether the manager is running. |
StrategyRegistry (Global strategy registry)
The global strategy registry is a singleton that maintains a group of strategy factory Blocks. Whenever a new AliPlayerController is created, all registered factories are instantiated and injected into the controller's StrategyManager using applyToManager:.
Method | Parameter | Description |
| - | Gets the global registry singleton. |
|
| Adds a global strategy factory. |
| - | Removes all global strategy factories, including built-in ones. |
|
| Instantiates all global strategies and registers them with the specified manager. |
| - | Restores the default built-in strategy configuration. |
Built-in strategies (FirstFrameStrategy, StutterDetectStrategy, and TrafficProtectionStrategy) are automatically registered on first access.
Built-in strategies
FirstFrameStrategy (Time-to-first-frame monitoring)
Measures the time from when the player starts preparing to when the first frame is rendered. It is divided into a preparing phase (Preparing to Prepared) and a rendering phase (Prepared to FirstFrameRendered).
Property | Type | Description |
|
| Callback delegate |
FirstFrameStrategyDelegate callback:
Method | Parameter | Description |
| strategy, prepareTimeMs, renderTimeMs, totalTimeMs | The first frame is rendered. |
StutterDetectStrategy (Stuttering detection)
Detects stuttering by listening for Loading events. Loading before the first frame is rendered is not counted.
Property | Type | Description |
|
| The number of stutters in the current session. |
|
| The total duration of stuttering in the current session, in milliseconds. |
|
| The stuttering threshold in milliseconds. Default: 0. |
|
| The callback delegate. |
|
| Creates a stutter detection strategy with a specified threshold. |
StutterDetectStrategyDelegate callback:
Method | Parameter | Description |
| strategy, durationMs | A stutter is detected. |
| strategy, stayDurationMs, validPlayDurationMs, totalStutterDurationMs, stutterCount | The playback session analysis is complete. |
TrafficProtectionStrategy (Traffic protection)
Monitors network status changes and detects playback on cellular networks. It only performs detection and logging and does not automatically pause playback.
Property | Type | Description |
|
| Specifies whether the device is currently on a cellular network. |
|
| The callback delegate. |
TrafficProtectionStrategyDelegate callback:
Method | Parameter | Description |
| strategy | Playback on a cellular network is detected. |
| strategy | The network is switched back to Wi-Fi. |
Log system
The log system provides a unified mechanism for log output and observer registration.
LogHub (Log center)
The log management center (singleton) that unifies log output and observer registration. It uses a hybrid threading model: console output is performed synchronously on the calling thread, while observer notifications are dispatched asynchronously to a background serial queue.
Properties
Property | Type | Default value | Description |
| BOOL | YES | Specifies whether to enable log output. |
| LogLevel | LogLevelInfo | The minimum log output level. |
| BOOL | YES | Specifies whether to enable console (NSLog) output. |
Observer management
Method | Parameter | Description |
| - | Gets the shared LogHub singleton. |
|
| Adds a log observer. It is held by a strong reference. |
|
| Removes a log observer. |
Log output
Method | Parameter | Description |
| tag, message | Outputs a Verbose level log. |
| tag, message | Outputs a Debug level log. |
| tag, message | Outputs an Info level log. |
| tag, message | Outputs a Warn level log. |
| tag, message | Outputs an Error level log. |
| tag, message, error (nullable) | Outputs an Error level log with an associated error object. |
| level, tag, message | Outputs a log at the specified level. |
Utility methods
Method | Parameter | Return value | Description |
|
|
| Converts a log level to an abbreviated string (V/D/I/W/E/N). |
|
|
| Converts a level name string back to an enumeration value. |
LogObserver (Log observer protocol)
Implement this protocol to receive all log output callbacks for custom log handling, such as writing to a file or reporting to a server.
Method | Parameter | Description |
|
| The log output callback. It is executed on a subthread. |
LogInfo (Log information model)
The data model for a single log entry.
Property | Type | Description |
|
| The log level. |
|
| The log tag. |
|
| The log message. |
|
| The timestamp. |
|
| The thread name. |
|
| The source file name. |
|
| The source code line number. |
|
| The associated error object. |
| - | Gets the formatted log string. |
Preloading system
The preloading system encapsulates the global preloading feature of the player SDK. You can retrieve it through `[AliPlayerKit preloader]`.
PlayerPreloader (Preloading protocol)
This protocol encapsulates the global preloading feature of the player SDK. You can retrieve it through [AliPlayerKit preloader].
Method | Parameter | Return value | Description |
| task, delegate |
| Adds a preloading task. |
|
|
| Cancels a specific task. |
|
|
| Pauses a specific task. |
|
|
| Resumes a specific task. |
| - |
| Cancels all preloading tasks. |
PlayerPreloadTask (Preloading task)
Property | Type | Description |
|
| The video data source. |
|
| The preloading configuration. |
| videoSource, preloadConfig | Creates a preloading task. |
PlayerPreloadConfig (Preloading configuration)
Property | Type | Default value | Description |
|
| 3000 | The preloading duration in milliseconds. |
|
| 0 | The preloading start position in milliseconds. |
|
|
| The default quality identifier. |
|
| 0 | The default resolution. 0 means no limit. |
|
| 0 | The default bitrate. 0 means no limit. |
|
| 0 | The network timeout in milliseconds. 0 uses the SDK default. |
|
| 0 | The number of network retries. 0 uses the SDK default. |
|
| nil | Referrer information. |
|
| nil | Custom request headers. |
Creation methods
Method | Parameter | Description |
| - | Creates a configuration with default settings. |
| preloadDuration, defaultQuality | Creates a configuration with a specified preloading duration and default quality. |
PreloadDelegate (Preloading delegate)
This protocol receives status events for preloading tasks. All methods are @required.
Callbacks may be triggered on a background thread. You must dispatch them to the main thread for processing.
Method | Parameter | Description |
| taskId, source | The preloading task is complete. |
| taskId, source, error | The preloading task failed. |
| taskId, source | The preloading task was canceled. |
Localization system
The localization system manages multilingual support for PlayerKit. It supports three modes: following the system language automatically, specifying a language manually, or using custom providers.
LocaleManager (Localization manager)
The localization manager (singleton) that manages multilingual support for PlayerKit.
Resolution Chain: Custom Provider (if injected) → Bundle for the manually specified language (Manual mode) → SDK Bundle that follows the system language → Returns the key itself as a fallback.
Properties
Property | Type | Description |
|
| The current language code. |
|
| The current language mode. |
|
| The currently injected custom provider. |
Methods
Method | Parameter | Description |
| - | Gets the singleton instance. |
|
| Sets the language manually. This switches to Manual mode. |
|
| Injects a custom provider. It is held by a weak reference. Pass `nil` to remove it. |
| - | Resets the language to follow the system language. |
|
| Queries a localized string. |
LocaleMode (Language mode)
Constant | Value | Description |
| 0 | Follows the system language. This is the default. |
| 1 | Manually specifies the language code. |
LocaleProvider (Localization provider protocol)
The host app can implement this protocol to provide custom translations for PlayerKit.
Method | Parameter | Return value | Description |
|
|
| Returns a localized string for a specified key. Returning `nil` means the SDK will handle it as a fallback. |
LocaleDidChangeNotification (Language change notification)
When the language mode or language code changes, a LocaleDidChangeNotification notification is sent on the main thread. The userInfo dictionary contains the new language code under the LocaleLanguageCodeKey key.
Key enumerations and constants
Core enumeration types used in AliPlayerKit.
PlayerState (Player state)
Constant | Value | Description |
| 0 | Idle. Initialized but no resource is loaded. |
| 1 | Preparing. Asynchronously loading resources. |
| 2 | Prepared. Ready to start playback. |
| 3 | Playing. |
| 4 | Paused. |
| 5 | Completed. |
| 6 | Stopped. |
| 7 | Error state. |
SceneType (Scenario type)
Constant | Value | Description |
| 0 | Video-on-demand scenario |
| 1 | Live streaming scenario. |
| 2 | Video list or short video stream scenario. |
| 3 | Restricted playback scenario. |
| 4 | Minimalist playback page scenario. |
ScaleMode (Scaling mode)
Constant | Value | Description |
| 0 | Stretches to fill the view. |
| 1 | Scales proportionally to fit the view. This may leave black bars. |
| 2 | Scales proportionally and crops to fill. |
MirrorMode (Mirror mode)
Constant | Value | Description |
| 0 | No mirroring. |
| 1 | Horizontal mirroring. |
| 2 | Vertical mirroring. |
RotateMode (Rotation mode)
Constant | Value | Description |
| 0 | 0 degrees. |
| 90 | 90 degrees. |
| 180 | 180 degrees. |
| 270 | 270 degrees. |
LogLevel (Log level)
Constant | Value | Description |
| 0 | The most detailed debug information. |
| 1 | Debug level. |
| 2 | Info level. This is the default. |
| 3 | Warning level. |
| 4 | Error level. |
| 100 | Disables all logs. |
TrackType (Track type)
Constant | Value | Description |
| 0 | Unknown. |
| 1 | Video track. |
| 2 | Audio track. |
| 3 | Caption track. |
| 4 | VOD track. |