AliPlayerWidget provides a comprehensive set of APIs for controlling the player's behavior. AliPlayerWidgetController exposes these APIs to support features such as playback control, status queries, and data updates.
Common APIs
Configuration and initialization
API name | Description |
| Configures the data source and initializes the player. |
| Manually triggers the player preparation process. |
| Destroys the player instance and releases all associated resources. |
Playback control
API name | Description |
| Starts video playback. |
| Pauses playback. |
| Stops playback and resets the player. |
| Seeks to a specified playback position. |
| Toggles the playback state between playing and paused. |
| Replays the video. Typically used to restart playback after it finishes. |
Playback properties
API name | Description |
| Sets the playback speed. |
| Sets the volume. |
| Adjusts the volume by a specified delta. |
| Sets the screen brightness. (The developer must implement the underlying logic.) |
| Adjusts the screen brightness by a specified delta. (The developer must implement the underlying logic.) |
| Sets whether the video loops. |
| Sets whether the player is muted. |
| Sets the mirror mode, such as horizontal or vertical mirroring. |
| Sets the rotation angle, such as 90° or 180°. |
| Sets the scaling mode, such as stretch or crop. |
Video quality switching
API name | Description |
| Switches the video quality. |
Thumbnails
API name | Description |
| Requests a thumbnail for a specified timestamp. |
Other features
These APIs have been moved to AliPlayerWidgetGlobalSetting. Use them directly:
Version number:
AliPlayerWidgetGlobalSetting.kWidgetVersion.Clear caches:
AliPlayerWidgetGlobalSetting.clearCaches().
Event notifications
AliPlayerWidgetController provides a series of ValueNotifier objects that deliver real-time notifications for player state changes and user interactions.
Playback state management
Notifier | Description |
| Notifies of changes to the playback state (e.g., playing, paused, or stopped). |
| Notifies of playback errors, providing an error code and message. |
| Notifies when the first frame is rendered. |
Playback progress management
Notifier | Description |
| Notifies of the current playback position in real time, in milliseconds. |
| Notifies of the buffering progress, indicating the range of cached content. |
| Notifies of the video's total duration, which can be used to calculate progress or display the video length. |
Volume and brightness control
Notifier | Description |
| Notifies of volume changes. The level ranges from 0.0 to 1.0. |
| Notifies of screen brightness changes. The level ranges from 0.0 to 1.0. |
| Notifies of changes to the playback speed. |
Playback property states
Notifier | Description |
| Notifies of changes to the loop status. |
| Notifies of changes to the mute status. |
| Notifies of changes to the mirror mode. |
| Notifies of changes to the rotation angle. |
| Notifies of changes to the scaling mode. |
Video quality and thumbnails
Notifier | Description |
| Notifies of changes to the current video quality (e.g., SD, HD, or UHD) and provides details after a switch. |
| Provides a list of all available video quality tracks. |
| Notifies of the thumbnail loading status, which allows for real-time previews when seeking. |
Subtitles
Notifier | Description |
| Notifies of changes to external subtitle information. |
| Notifies of changes to the index of the current subtitle track. |
| Notifies of changes to subtitle visibility. |
Other states
Notifier | Description |
| Notifies of changes to the video dimensions. |
| Notifies of changes to the snapshot file state. |
| Notifies of changes to the download state. |
Usage
To update the UI or execute logic in real time, use a ValueListenableBuilder to listen for changes from a ValueNotifier.
// Listen for playback errors
ValueListenableBuilder<Map<int?, String?>?>(
valueListenable: _controller.playErrorNotifier,
builder: (context, error, _) {
if (error != null) {
final errorCode = error.keys.firstOrNull;
final errorMsg = error.values.firstOrNull;
return Text("Playback error: [$errorCode] $errorMsg");
}
return const SizedBox.shrink();
},
);API documentation
For detailed API documentation and usage instructions, see the official documentation on Pub:
Official source: API reference on pub.dev.
Domestic mirror: API reference on pub.flutter-io.cn.
The official documentation provides detailed descriptions for each API, including parameters, return values, and additional usage examples.