The slot system is a core architectural design of AliPlayerKit. It uses componentization and a pluggable mechanism to break down the player UI into independent slot components. This approach decouples the interface, allowing for flexible composition and extension.
Slot types
The system provides the following slot types, listed in stacking order from bottom to top:
Slot type | Default order | Description | Default visibility |
playerSurface | 10 | The player surface slot for displaying video content. (Customization not recommended) | Yes |
subtitle | 20 | The subtitle slot for displaying video subtitles. | Yes (conditional) |
coverImage | 30 | The cover image slot for displaying an image before the video loads. | Yes (conditional) |
playControl | 40 | The playback control slot for handling gesture controls. | Yes |
topBar | 50 | The top bar slot, which typically contains the back button, title, and settings button. | Yes |
bottomBar | 60 | The bottom bar slot, which typically contains playback controls, a progress bar, and the full-screen button. | Yes |
seekThumbnail | 70 | The seek thumbnail slot for displaying a preview thumbnail when the progress bar is dragged. | Yes (conditional) |
centerDisplay | 80 | The center display slot for showing information like volume and brightness during gesture operations. | Yes (conditional) |
playState | 90 | The playback state slot for displaying status information, such as playback errors. | Yes (conditional) |
settingMenu | 100 | The settings menu slot, which contains player settings options. | Yes (conditional) |
overlays | 110 | The overlays slot, on the topmost layer, is used for adding custom content such as 'Like', 'Comment', and 'Share' elements. | No |
Default order: The lower the value, the lower the layer. Built-in slots have an order spacing of 10, leaving ample room to insert custom slots.
The
playerSurfaceslot renders video content. Do not customize this slot, as modification can cause the player to malfunction.
Usage
Default UI
The player uses the built-in default UI by default, requiring no configuration:
AliPlayerWidget(controller)Customize slots
Use the slotBuilders parameter to customize any slot. Unspecified slots use the default UI.
Partial customization
Replace only the slots you need to customize and keep the rest as default:
AliPlayerWidget(
controller,
slotBuilders: {
SlotType.topBar: (context) => MyCustomTopBar(),
},
)Full customization
Customize all slots to build a fully tailored UI:
AliPlayerWidget(
controller,
slotBuilders: {
// Note: Customizing playerSurface is not recommended.
SlotType.topBar: (context) => MyCustomTopBar(),
SlotType.bottomBar: (context) => MyCustomBottomBar(),
SlotType.playControl: (context) => MyPlayControl(),
SlotType.coverImage: (context) => MyCoverImage(),
SlotType.playState: (context) => MyPlayState(),
SlotType.centerDisplay: (context) => MyCenterDisplay(),
SlotType.seekThumbnail: (context) => MySeekThumbnail(),
SlotType.subtitle: (context) => MySubtitle(),
SlotType.settingMenu: (context) => MySettingMenu(),
SlotType.overlays: (context) => MyOverlays(),
},
)SlotWidgetBuilder type
The slot system currently uses a concise builder signature:
// Current signature (recommended)
typedef SlotWidgetBuilder = Widget Function(BuildContext context);
// Legacy signature (deprecated)
@Deprecated('Please use SlotWidgetBuilder instead')
typedef SlotWidgetBuilderWithController = Widget Function(
BuildContext context,
AliPlayerWidgetController controller,
);The current design uses a single shared Controller model. Full-screen and normal modes share the same Controller instance, so you do not need to pass it via the builder parameter.
To access the Controller in a custom slot, reference it directly from outside the builder.
Hide slots
Set a slot's builder to null to hide that slot:
AliPlayerWidget(
controller,
slotBuilders: {
SlotType.topBar: null,
SlotType.bottomBar: null,
},
)Fine-grained control
To hide specific elements (such as buttons) in a default slot without replacing the entire slot, use hiddenSlotElements:
AliPlayerWidget(
controller,
hiddenSlotElements: const {
// Hide the Download and Snapshot buttons in the top bar
SlotType.topBar: {
TopBarElements.download,
TopBarElements.snapshot,
},
// Disable double-tap and vertical swipe gestures in playback control
SlotType.playControl: {
PlayControlElements.doubleTap,
PlayControlElements.leftVerticalDrag,
PlayControlElements.rightVerticalDrag,
},
},
)hiddenSlotElements applies only to the default slot. If you customize a slot by using slotBuilders, the hiddenSlotElements configuration for that slot is ignored.
Custom UI and layer control
Unlike traditional overlay-only solutions, the slot system lets you insert custom UI components at any layer in the player, not just the top one. Use defaultOrder to control the rendering order with precision. This lets you place components such as watermarks, bullet screens, and ads at the exact layer you need:
SlotType is an extensible class. You can create custom slot types and control their layer position using defaultOrder:
// Create a custom slot type and set its layer order between coverImage (30) and playControl (40).
const myWatermark = SlotType('watermark', defaultOrder: 35);
AliPlayerWidget(
controller,
slotBuilders: {
myWatermark: (context) => MyWatermarkWidget(),
},
// All slots are automatically sorted by defaultOrder; no manual enumeration is required.
)The system automatically sorts all built-in and custom slots by their defaultOrder value.
How it works
The slot system uses a three-level rendering strategy:
Custom first: The system uses any custom builder provided for a slot.
Default fallback: The system uses its default builder if no custom one is provided.
Explicitly hidden: The system hides a slot if its builder is null.
Scene adaptation
The behavior of certain slots automatically adapts based on the playback scene (SceneType):
vod (VOD scene): All slot functions are supported.
live (live scene): Slot functions for progress bar dragging are disabled.
listPlayer (list player scene): Slot functions for vertical gestures are disabled.
restricted (restricted playback scene): Slot functions for timeline operations are disabled.
minimal (minimal playback scene): Only the
playerSurfaceslot appears.
Example
For a complete example of using the slot system, see example/lib/pages/slot/slot_demo_page.dart.
The slot system makes it easy to create a player UI for a wide range of use cases.