This topic describes the main AliPlayerKit APIs. It covers core APIs, the slot system, video sources, player interfaces, state storage, the event system, the logging system, preload interfaces, lifecycle policies, and the strategy system.
AliPlayerKit provides complete code comments for all core APIs—including classes and methods. In IDEs such as Android Studio, you can view these comments using hover tips or Quick Documentation features to improve development efficiency. These comments also make the APIs more accessible to AI programming tools, helping them better understand API semantics.
Core APIs
AliPlayerKit (Global Interface)
The AliPlayerKit class provides global configuration and initialization. It is the only global entry point for the entire player framework.
Initialization methods
Method | Parameter | Return value | Description |
| context: application context | void | Initialize global settings. Call this method in Application.onCreate(). |
Status Query
Method | Parameter | Return value | Description |
| - | boolean | Check whether initialization is complete. |
| - | Context | Get the application context. |
| - | String | Get the Kit version number. |
| - | String | Get the underlying SDK version number. |
| - | String | Get the device ID. |
Configuration methods
Method | Parameter | Return value | Description |
| enable: Specifies whether the feature is enabled. | void | Enable or disable debug mode. |
| - | boolean | Check whether debug mode is enabled. |
| enable: set to true to enable | void | Show or hide the log panel. |
| - | boolean | Check whether the log panel is enabled. |
| disable: Specifies whether the feature is disabled. | void | Enable or disable screenshots. |
| - | boolean | Check whether screenshots are disabled. |
| viewType: view type | void | Set the player view type. |
| - | PlayerViewType | Get the current player view type. |
Cache management
Method | Parameter | Return value | Description |
| - | void | Clear player caches. |
Global APIs
Method | Parameter | Return value | Description |
| - | IPlayerLogger | Get the global logger instance. |
| - | IPlayerPreloader | Get the global preloader instance. |
| logger: logger instance | void | Set a custom logger implementation. |
| preloader: preloader instance | void | Set a custom preloader implementation. |
AliPlayerView (View Component)
The AliPlayerView class is the core player view component. It handles UI rendering and slot management. As the View layer in the MVC architecture, it renders the player UI and manages UI components.
Controller binding
Method | Parameter | Return value | Description |
| controller, model | void | Bind the controller and data using the default UI. |
| controller, model, registry | void | Bind the controller and data using a custom UI. |
| - | void | Unbind and release resources. |
Lifecycle
Method | Parameter | Return value | Description |
| lifecycleOwner | boolean | Bind the lifecycle. |
Other methods
Method | Parameter | Return value | Description |
| - | boolean | Handle the back button press. Return true if handled. |
| - | ISlotManager | Get the slot manager. |
AliPlayerController (Controller)
The AliPlayerController class controls playback logic and state management. As the Controller layer in the MVC architecture, it coordinates interactions between the View and Model layers.
Constructors
Method | Parameter | Description |
| context: application context | Create a controller using the default lifecycle policy. |
| context, lifecycleStrategy | Create a controller using a custom lifecycle policy. |
Configuration and initialization
Method | Parameter | Return value | Description |
| model: playback data | void | Configure playback data. |
| - | AliPlayerModel | Get the current playback data configuration. |
| - | IMediaPlayer | Get the player instance. |
| - | void | Destroy the player. |
State management
Method | Parameter | Return value | Description |
| - | IPlayerStateStore | Get the player state store. |
| - | StrategyManager | Get the strategy manager. |
View settings
Method | Parameter | Return value | Description |
| displayView | void | Set the display view. |
| surface | void | Set the Surface. |
| - | void | Notify that the Surface has changed. |
Lifecycle methods
Method | Parameter | Return value | Description |
| - | void | Manually resume playback outside a LifecycleOwner context. |
| - | void | Manually pause playback outside a LifecycleOwner context. |
AliPlayerModel (Data Model)
The AliPlayerModel class encapsulates playback configuration data. As the Model layer in the MVC architecture, it holds all configuration data required by the player. Use the Builder pattern to create instances.
Builder methods
Method | Parameter | Description |
| video source object | Set the video source. Required. |
| scene type | Set the playback scene type. |
| thumbnail URL | Set the thumbnail URL. |
| video title | Set the video title. |
| Autoplay | Set whether to enable autoplay. |
| trace ID | Set the trace ID. |
| start position | Set the start position in milliseconds. |
| Is hardware decoding enabled? | Set whether to enable hardware decoding. |
| Is hibernation supported? | Set whether to allow screen sleep. |
| - | Build an AliPlayerModel instance. |
Property accessors
Method | Return value | Description |
| VideoSource | Get the video source object. |
| int | Get the playback scene type. |
| String | Get the thumbnail URL. |
| String | Get the video title. |
| boolean | Get whether autoplay is enabled. |
| String | Get the trace ID. |
| long | Get the start position. |
| boolean | Get whether hardware decoding is enabled. |
| boolean | Get whether screen sleep is allowed. |
Slot System
The slot system is AliPlayerKit’s UI extension mechanism. It lets you customize individual UI components of the player.
ISlotManager (Slot Management Interface)
The ISlotManager interface provides slot management capabilities. Retrieve it from AliPlayerView.getSlotManager().
Method
Parameter
Return value
Description
rebuildSlots()-
void
Rebuild all slots after modifying the SlotRegistry.
getSlotView(SlotType)slotType: slot type
View
Get the slot view for the specified type.
bindData(AliPlayerModel)model: playback data
void
Bind playback data to the slot system.
unbindData()-
void
Unbind playback data.
updateSceneType(int)sceneType: scene type
void
Update the scene type and rebuild slots.
SlotRegistry (Slot Registry)
The SlotRegistry class registers custom slots. Pass it into AliPlayerView.attach().
Registration methods
Method | Parameter | Description |
| type, builder | Register a slot builder. |
| type, slotClass | Register a slot class. The class is created using reflection. |
| type, layoutId | Register a layout resource as a slot. |
Management methods
Method | Return value | Description |
| SlotBuilder | Unregister a slot builder. |
| boolean | You can check if it is registered. |
| void | Clear all registrations. |
| int | Get the number of registered slots. |
ISlot (Slot Interface)
Custom slots must implement the ISlot interface to define their lifecycle.
Method | Description |
| Called when the slot is attached to its host. |
| Called when the slot is detached from its host. |
| Called when playback data is bound. |
| Called when playback data is unbound. |
We recommend extending BaseSlot to implement custom slots. The framework automatically manages event subscription lifecycles.
SlotType (Slot Types)
Constant | Description |
| Player surface view slot: the core view used to render video content. |
| Fullscreen management slot: manages fullscreen toggle logic. |
| Gesture control slot: handles gesture controls such as tap, double-tap, long press, and drag. |
| Landscape viewing hint slot: prompts users to watch landscape videos in fullscreen. |
| Cover image slot: displays the video cover image. |
| Center display slot: displays status information in the center area, such as playback speed, brightness, and volume. |
| Playback state slot: displays playback state information such as error messages and loading indicators. |
| Log panel slot: displays player log information for debugging. |
| Top control bar slot: displays the back button, title, and settings. |
| Bottom control bar slot: displays playback controls, the progress bar, and the fullscreen toggle. |
| Settings menu slot: displays the settings menu, including playback speed, definition, mirroring, and rotation options. |
SceneType (Playback Scenes)
Constant | Value | Description |
| 0 | Video-on-demand scene: standard video playback with full playback controls. |
| 1 | Live streaming scene: real-time stream playback without seeking or speed control. |
| 2 | Video list scene: player used in a video list. Disables vertical gestures. |
| 3 | Restricted playback scene: limits timeline operations. Used in education and training. |
| 4 | Minimal playback scene: shows only the playback view with no UI elements. |
PlayerViewType (Player View Types)
Constant | Description |
| AliDisplayView (recommended): official display view component with better compatibility and performance. |
| SurfaceView: uses a separate rendering thread but does not support animations. |
| TextureView: supports animations and transformations. Best for scenes requiring view animations. |
Video Sources
VideoSourceFactory (Video Source Factory)
Method | Parameter | Return value | Description |
| vid, playAuth | VideoSource | Create a VidAuth video source (recommended). |
| vid, accessKeyId, accessKeySecret, securityToken, region | VideoSource | Create a VidSts video source. |
| url: video URL | VideoSource | Create a URL video source. |
In production environments, use the VidAuth method. It offers higher security and integrates with Alibaba Cloud VOD services for enhanced playback capabilities. For more information, see Multiple video source support.
VideoSource (Video Source)
Method | Return value | Description |
| boolean | Check whether the video source is valid. |
| int | Get the video source type. |
| String | Get the video source ID. |
Player Interfaces
IMediaPlayer (Media Player Interface)
The IMediaPlayer interface defines core player operations. Retrieve it from AliPlayerController.getPlayer().
Playback controls
Method | Parameter | Description |
| - | Start playback. |
| - | Pause playback. |
| - | Toggle between playing and pausing. |
| - | Stop playback. |
| - | Replay the video. |
| positionMs | Seek to the specified position in milliseconds. |
| - | Release player resources. |
Data sources
Method | Parameter | Description |
| model | Set the video data source. |
View settings
Method | Parameter | Description |
| displayView | Set the display view. |
| surface | Set the rendering Surface. |
| - | Notify that the Surface has changed. |
Playback settings
Method | Parameter | Description |
| speed | Set the playback speed (0.3 to 3.0). |
| loop | Enable or disable looping. |
| mute | Mute. |
| scaleType | Set the rendering fill mode. |
| mirrorType | Set the mirroring mode. |
| rotation | Set the rotation angle. |
| trackQuality | Select the video definition. |
| - | Capture a screenshot. |
State queries
Method | Return value | Description |
| String | Get the unique player identifier. |
| IPlayerStateStore | Get the state store interface. |
ScaleType (Rendering Fill Modes)
Constant | Value | Description |
| 0 | Stretch to fill the view. |
| 1 | Fit while preserving aspect ratio (may show black bars). |
| 2 | Crop to fill while preserving aspect ratio. |
MirrorType (Mirroring Modes)
Constant | Value | Description |
| 0 | No mirroring. |
| 1 | Horizontal mirroring. |
| 2 | Vertical mirroring. |
Rotation (Rotation Angles)
Constant | Value | Description |
| 0 | 0 degrees. |
| 90 | 90 degrees. |
| 180 | 180 degrees. |
| 270 | 270 degrees. |
State Storage Interface
IPlayerStateStore (Player State Storage)
The IPlayerStateStore interface provides read-only access to player state. Retrieve it from AliPlayerController.getStateStore() or IMediaPlayer.getStateStore().
Playback state
Method | Return value | Description |
| PlayerState | Get the current playback state. |
| long | Get the total video duration in milliseconds. |
| long | Get the current playback position in milliseconds. |
| float | Get the current playback speed. |
Video settings
Method | Return value | Description |
| VideoSize | Get the video size (may be null). |
| int | Get the current rotation angle. |
| int | Get the current fill mode. |
| int | Get the current mirroring mode. |
Playback settings
Method | Return value | Description |
| boolean | Check whether looping is enabled. |
| boolean | Check whether audio is muted. |
| boolean | Check whether the player is in fullscreen mode. |
Definition
Method | Return value | Description |
| List | Get the list of available definitions. |
| int | Get the index of the current definition. |
PlayerState (Playback States)
Constant | Description |
| Unknown state: the player state is unknown or uninitialized. |
| Idle state: the player is created but not yet initialized, or resources are released. |
| Initializing: the player is initializing and preparing to load video resources. |
| Initialized: the player is fully initialized but not yet ready to play. |
| Preparing: the player is preparing video resources and parsing video information. |
| Prepared: the player is ready to start playback. |
| Playing: the player is actively playing video. |
| Paused: the player is paused. |
| Completed: the video playback is finished. |
| Stopped: the player is stopped. |
| Error: an error occurred during playback. |
Event System
PlayerEventBus (Event Bus)
The PlayerEventBus class is the global event bus for publishing and subscribing to player events.
Subscription methods
Method | Parameter | Description |
| eventType, listener | Subscribe to events of the specified type. |
| eventType, listener | Unsubscribe from events of the specified type. |
| listener | Unsubscribe the listener from all event types. |
| - | Clear all subscriptions. Use with caution. |
Publishing methods
Method | Parameter | Description |
| event | Publish an event. |
Query methods
Method | Return value | Description |
| int | Get the number of subscribers for the specified event type. |
| boolean | Check whether any subscribers exist for the specified event type. |
PlayerCommand (Player Commands)
Player commands control player behavior. Publish them using PlayerEventBus.post().
Command class | Parameter | Description |
| playerId | Play command. |
| playerId | Pause command. |
| playerId | Toggle between playing and pausing. |
| playerId | Stop command. |
| playerId | Replay command. |
| playerId, position | Seek command. Position is in milliseconds. |
| playerId, speed | Set the playback speed (0.3 to 3.0). |
| playerId | Screenshot command. |
| playerId, loop | Set looping. |
| playerId, mute | Set mute. |
| playerId, scaleType | Set the rendering fill mode. |
| playerId, mirrorType | Set the mirroring mode. |
| playerId, rotation | Set the rotation angle. |
| playerId, trackQuality | You can switch resolution. |
Usage example
// Post a play command.
PlayerEventBus.getInstance().post(new PlayerCommand.Play(playerId));
// Post a seek command.
PlayerEventBus.getInstance().post(new PlayerCommand.Seek(playerId, 5000));
// Set the playback speed.
PlayerEventBus.getInstance().post(new PlayerCommand.SetSpeed(playerId, 1.5f)); PlayerEvents (Player Events)
Player state changes are published as events. Subscribe to listen for them.
Event class | Property | Description |
| oldState, newState | Playback state changed. |
| duration | Player is prepared. |
| - | First frame rendered. |
| width, height | Video size changed. |
| duration, currentPosition, bufferedPosition | Playback information updated. |
| errorCode, errorMsg | Error event. |
| - | Loading started. |
| percent, netSpeed | Loading progress. |
| - | Loading finished. |
| speed | Set speed completed. |
| result, snapshotPath, width, height | Screenshot completed. |
| loop | Set loop completed. |
| mute | Set mute completed. |
| scaleType | Set fill mode completed. |
| mirrorType | Set mirroring completed. |
| rotation | Set rotation completed. |
| trackQualityList | Definition list updated. |
| trackIndex | Definition selection completed. |
Usage example
// Subscribe to a playback event.
PlayerEventBus.getInstance().subscribe(PlayerEvents.Prepared.class, event -> {
long duration = event.duration; // Total video duration
});
// Subscribe to an error event.
PlayerEventBus.getInstance().subscribe(PlayerEvents.Error.class, event -> {
int code = event.errorCode;
String msg = event.errorMsg;
}); Logging System
IPlayerLogger (Logging Interface)
The IPlayerLogger interface provides global logging configuration. Retrieve it from AliPlayerKit.getLogger().
Method | Parameter | Return value | Description |
| enable | void | Enable or disable console logging. |
| - | boolean | Check whether console logging is enabled. |
| level | void | Set the log level. |
| - | int | Get the current log level. |
| callback | void | Set the log callback listener. |
LogLevel (Log Levels)
Constant | Value | Description |
| 0 | Most detailed level. Logs all debug information. |
| 1 | Debug level. |
| 2 | Information level. |
| 3 | Warning level. |
| 4 | Error level. |
| 100 | Disable all logs. |
Preload Interfaces
IPlayerPreloader (Preload Interface)
The IPlayerPreloader interface provides global preload management. Retrieve it from AliPlayerKit.getPreloader().
Method | Parameter | Return value | Description |
| task, listener | String | Add a preload task and return its ID. |
| taskId | void | Cancel the specified task. |
| taskId | void | Pause the specified task. |
| taskId | void | Resume the specified task. |
PreloadCallback (Preload Callback)
Method | Parameter | Description |
| taskId, source | Preload completed. |
| taskId, source, code, message | Preload error. |
| taskId, source | Preload canceled. |
Player Lifecycle Policies
IPlayerLifecycleStrategy (Player Lifecycle Policy Interface)
The IPlayerLifecycleStrategy interface defines how player instances are managed across their lifecycle. It optimizes player instance creation and reuse.
Method | Parameter | Return value | Description |
| factory | void | Initialize the policy. |
| context, uniqueId | IMediaPlayer | Get a player instance. |
| player, uniqueId, force | void | Recycle a player instance. |
| - | void | Clear all resources. |
| context, count | void | Preload player instances. |
Built-in policies
Policy class | Description |
| Default policy: create a new instance each time and destroy it immediately after use. |
| Reuse pool policy: best for streaming lists of videos. |
| ID-scoped policy: bind one instance to one ID. |
| Singleton policy: one global instance only. |
For more information, see Player lifecycle policies.
Strategy System
StrategyManager (Strategy Manager)
The StrategyManager class manages the lifecycle of all strategies. Retrieve it from AliPlayerController.getStrategyManager().
Method | Parameter | Return value | Description |
| strategy | void | Register a strategy. |
| strategy | void | Unregister Policy |
| name | IStrategy | Get a strategy by name. |
| context | void | Start all strategies. |
| - | void | Stop all strategies. |
| - | void | Reset all strategies. |
| context | void | Update the context and restart strategies. |
| - | void | Delete Manager |
| - | int | Get the number of registered strategies. |
| - | boolean | You can check whether it has started. |
IStrategy (Strategy Interface)
Method | Description |
| Get the strategy name. |
| Called when the strategy starts. |
| Called when the strategy stops. |
| Called when the strategy resets. |