Slot system

Updated at:

The Slot System is a core architectural design of AliPlayerKit. It uses a component-based, pluggable mechanism to deconstruct the player User Interface (UI) into multiple independent slot components. This design decouples the UI and allows for flexible composition and extension.

Introduction to concepts

What is the Slot System?

The Slot System is an architectural mechanism that provides centralized management for slots. It is responsible for slot registration, lifecycle management, scenario adaptation, rendering order, and runtime state control. This mechanism lets you quickly build a UI with default slots or customize components as needed. You can replace, extend, or completely redefine components to create a highly customized player interface.

What is a slot?

A slot is a basic building block of the player UI. It represents an independent UI component, such as a top control bar, a bottom progress bar, or a thumbnail. All slots are layered according to a predefined Z-Order to form the complete UI. Each slot focuses only on its own display and interaction logic. This design creates a structure with clear responsibilities and controllable granularity.

Core value

The Slot System deconstructs player UI components into independent parts. This gives developers the freedom to choose how to use them.

Usage

Description

Advantage

Use the default interface

Zero configuration, out-of-the-box

Simplifies the integration process with low-code integration.

Customize some slots

Replace only the slots that need customization and keep the others as default.

Allows for partial customization while retaining default interactions.

Fully customize the interface

Replace all slot implementations.

Meets requirements for a brand-specific UI.

Architectural advantages:

  • Decoupling: UI components are separated from the core player logic, which results in clear responsibilities.

  • Flexibility: UI components can be dynamically composed and replaced at runtime.

  • Extensibility: You can customize the UI without modifying the framework, which provides strong extensibility.

  • Separation of concerns: UI styles, such as XML layouts, are separated from business logic, which is handled by Slot classes.

Features

Core capabilities

Capability

Description

Dynamic composition

Freely combine UI components at runtime.

Hot swapping

Replace component implementations without a restart.

Scene adaptation

Automatically switch UI behavior for different playback scenarios.

Dual lifecycle

Manage the View lifecycle and Data lifecycle independently.

Built-in slot types

AliPlayerKit includes 11 built-in slot types, arranged by Z-Order from bottom to top:

Slot type

Enumeration value

Description

Default implementation

Video display

SlotTypePlayerSurface (10)

Displays the player's video content (bottom layer).

PlayerSurfaceSlot

Gesture control

SlotTypeGestureControl (20)

Handles single-tap, double-tap, long-press, and drag gestures.

GestureControlSlot

Landscape hint

SlotTypeLandscapeHint (30)

Prompts users to watch in full screen when a landscape video is played in portrait mode.

LandscapeHintSlot

Cover

SlotTypeCover (40)

Displays the video thumbnail before playback starts.

CoverSlot

Center display

SlotTypeCenterDisplay (50)

Displays status indicators for playback speed, brightness, volume, and more.

CenterDisplaySlot

Play state

SlotTypePlayState (60)

Displays loading, error, or playback completion states.

PlayStateSlot

Log panel

SlotTypeLogPanel (70)

Displays player logs for debugging.

LogPanelSlot

Top control bar

SlotTypeTopBar (80)

Includes the back button, title, and settings button.

TopBarSlot

Bottom control bar

SlotTypeBottomBar (90)

Includes the play/pause button, progress bar, and full screen button.

BottomBarSlot

Settings menu

SlotTypeSettingMenu (100)

Includes playback speed, definition, image, and rotation settings.

SettingMenuSlot

Option panel

SlotTypeOptionPanel (110)

A pop-up panel for playback speed and definition options (top layer).

OptionPanelSlot

Note

The enumeration values are incremented by 10. This allows new types to be inserted later without affecting the existing order. The enumeration value also determines the Z-axis order of the slot. A smaller value places the slot lower in the stack. You can use the SlotTypeName() function to retrieve the readable name of a slot type. You can use the SlotTypeAllBuiltinTypes() function to retrieve an ordered array of all built-in types.

Z-Order layer diagram

┌────────────────────────────────────────┐  ← Topmost layer
│       OptionPanel                      │  Z=110
├────────────────────────────────────────┤
│       SettingMenu                      │  Z=100
├────────────────────────────────────────┤
│       BottomBar                        │  Z=90
├────────────────────────────────────────┤
│       TopBar                           │  Z=80
├────────────────────────────────────────┤
│       LogPanel                         │  Z=70
├────────────────────────────────────────┤
│       PlayState                        │  Z=60
├────────────────────────────────────────┤
│       CenterDisplay                    │  Z=50
├────────────────────────────────────────┤
│       Cover                            │  Z=40
├────────────────────────────────────────┤
│       LandscapeHint                    │  Z=30
├────────────────────────────────────────┤
│       GestureControl                   │  Z=20
├────────────────────────────────────────┤
│       PlayerSurface                    │  Z=10
└────────────────────────────────────────┘  ← Bottommost layer

Scene adaptation

AliPlayerKit defines five playback scenarios. The visibility and behavior of slots automatically adapt to different scenarios. Scenario adaptation is implemented through SlotConfig. DefaultSlotFactory provides predefined default configurations for all built-in slots.

Scenario

Enumeration value

Description

Typical application

VOD

SceneTypeVOD

Video-on-demand scenario, supports all features.

Standard video playback

LIVE

SceneTypeLive

Live streaming scenario, disables timeline operations.

Real-time live stream

VIDEO_LIST

SceneTypeVideoList

List playback scenario, disables vertical gestures.

News feed, short video list

RESTRICTED

SceneTypeRestricted

Restricted playback scenario, limits seeking.

Education, training, and exam monitoring

MINIMAL

SceneTypeMinimal

Minimal playback scenario, displays only the video surface.

Background video, decorative video

Slot visibility rules (defined by DefaultSlotFactory.defaultConfigs):

Slot

VOD

LIVE

VIDEO_LIST

RESTRICTED

MINIMAL

PlayerSurface

✓

✓

✓

✓

✓

GestureControl

✓

✓

✓

✓

✗

LandscapeHint

✓

✓

✓

✓

✗

Cover

✓

✗

✓

✗

✗

CenterDisplay

✓

✓

✓

✓

✗

PlayState

✓

✓

✓

✓

✓

LogPanel

Configurable

Configurable

Configurable

Configurable

✗

TopBar

✓

✓

✓

✓

✗

BottomBar

✓

✓

✓

✓

✗

SettingMenu

✓

✓

✓

✓

✗

OptionPanel

✓

✓

✓

✓

✗

Differences in gesture behavior:

Gesture

VOD

LIVE

VIDEO_LIST

RESTRICTED

MINIMAL

Single-tap

Show/hide control bars

Show/hide control bars

Show/hide control bars

Show/hide control bars

Disabled

Double-tap

Toggle play/pause

Toggle play/pause

Toggle play/pause

Toggle play/pause

Disabled

Long-press

Play at 2x speed

Disabled

Play at 2x speed

Disabled

Disabled

Horizontal drag

Seek

Disabled

Seek

Disabled

Disabled

Left vertical drag

Adjust brightness

Adjust brightness

Disabled

Adjust brightness

Disabled

Right vertical drag

Adjust volume

Adjust volume

Disabled

Adjust volume

Disabled

Usage

Strategy 1: Use the default interface

This is the simplest way to use the system. It is an out-of-the-box solution that requires zero configuration.

@implementation PlayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 1. Create the player view.
    AliPlayerView *playerView = [[AliPlayerView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:playerView];

    // 2. Create the controller.
    AliPlayerController *controller = [[AliPlayerController alloc] init];

    // 3. Create the data model.
    AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:videoSource];
    model.sceneType = SceneTypeVOD;
    model.autoPlay = YES;

    // 4. Configure and attach (automatically uses default slots).
    [controller configure:model];
    [playerView attach:controller];
}

@end

Strategy 2: Customize some slots

You can replace only the slots that require customization and use the default implementations for the others.

// 1. Get the SlotManager of the player view.
SlotManager *slotManager = playerView.slotManager;

// 2. Register only the slots you want to customize (others remain default).
[slotManager registerSlotType:SlotTypeTopBar provider:^UIView<SlotProtocol> *(UIView *parentView) {
    return [[MyCustomTopBarSlot alloc] initWithFrame:parentView.bounds];
}];

// 3. Configure and attach.
[controller configure:model];
[playerView attach:controller];

Strategy 3: Fully customize the interface

You can clear all default configurations and register custom slots one by one.

// 1. Get the SlotManager and clear the default configurations.
SlotManager *slotManager = playerView.slotManager;
[slotManager clearAll];

// 2. Register all required custom slots.
[slotManager registerSlotType:SlotTypePlayerSurface provider:^UIView<SlotProtocol> *(UIView *parentView) {
    return [[MySurfaceSlot alloc] initWithFrame:parentView.bounds];
}];
[slotManager registerSlotType:SlotTypeCover provider:^UIView<SlotProtocol> *(UIView *parentView) {
    return [[MyCoverSlot alloc] initWithFrame:parentView.bounds];
}];
// ... other slots

// 3. Attach.
[controller configure:model];
[playerView attach:controller];

Slot visibility control

You can control whether a slot is shown or hidden without replacing its implementation.

SlotManager *slotManager = playerView.slotManager;

// Hide the entire slot (it will not be built when rebuildSlots is called).
[slotManager hideSlot:SlotTypeLogPanel];

// Show a previously hidden slot (you must call rebuildSlots for this to take effect).
[slotManager showSlot:SlotTypeLogPanel];
[slotManager rebuildSlots];

// Check if a slot is hidden.
BOOL hidden = [slotManager isSlotHidden:SlotTypeLogPanel];

Element-level visibility control

The Slot System supports fine-grained visibility control for individual UI elements within a slot. This is achieved using a bitmask (SlotElements.h).

SlotManager *slotManager = playerView.slotManager;

// Hide the download and snapshot buttons in the top bar.
[slotManager hideElements:(TopBarElementDownload | TopBarElementSnapshot)
                  forSlot:SlotTypeTopBar];

// Hide the refresh button in the bottom bar.
[slotManager hideElements:BottomBarElementRefresh
                  forSlot:SlotTypeBottomBar];

// Disable the horizontal drag gesture (for the GestureControl slot, hiding an element means disabling the corresponding gesture).
[slotManager hideElements:GestureElementHorizontalDrag
                  forSlot:SlotTypeGestureControl];

// Show a previously hidden element.
[slotManager showElements:TopBarElementDownload
                  forSlot:SlotTypeTopBar];

// Batch set hidden elements for all slots (replaces existing settings).
[slotManager setAllHiddenElementMasks:@{
    @(SlotTypeTopBar): @(TopBarElementDownload | TopBarElementSnapshot),
    @(SlotTypeBottomBar): @(BottomBarElementRefresh),
}];

// Clear all element visibility configurations.
[slotManager clearAllElementMasks];

Element bitmask types:

Slot type

Element type

Controllable elements

TopBar

TopBarElement

Back / Title / Download / Snapshot / Settings

BottomBar

BottomBarElement

Play / Progress / Refresh / Speed

SettingMenu

SettingMenuElement

Speed / TrackInfo / Loop / Mute / MirrorMode / RotateMode / ScaleMode / Subtitle

CenterDisplay

CenterDisplayElement

Volume / Brightness / Speed

GestureControl

GestureElement

SingleTap / DoubleTap / LongPress / HorizontalDrag / LeftVerticalDrag / RightVerticalDrag

PlayState

PlayStateElement

ErrorMessage / LoadingMessage

Note

Each slot subclass declares its default visible elements through onRegisterElements. You can override the default visibility using hideElements:forSlot: to hide elements or showElements:forSlot: to show elements. The final visibility is queried using isElementVisible:.

Scene visibility configuration

You can use SlotConfig to control the visibility of slots in different scenarios.

SlotManager *slotManager = playerView.slotManager;

// Configure the cover slot to be invisible in the Live and Restricted scenarios.
SlotConfig *coverConfig = [SlotConfig configWithSlotType:SlotTypeCover
                                         excludedScenes:[NSSet setWithObjects:@(SceneTypeLive), @(SceneTypeRestricted), nil]];
[slotManager registerSlotConfig:coverConfig];

// Use visibilityCondition for dynamic visibility control.
SlotConfig *logConfig = [SlotConfig configWithSlotType:SlotTypeLogPanel
                                       excludedScenes:[NSSet setWithObject:@(SceneTypeMinimal)]
                                  visibilityCondition:^BOOL{
    return [AliPlayerKit isDebugModeEnabled];
}];
[slotManager registerSlotConfig:logConfig];

// Remove the scene visibility configuration (the slot will be visible in all scenarios).
[slotManager unregisterSlotConfigForType:SlotTypeCover];

// Query the configuration.
SlotConfig *config = [slotManager slotConfigForType:SlotTypeCover];
BOOL visible = [config isVisibleInScene:SceneTypeLive];
Note

DefaultSlotFactory.defaultConfigs provides predefined default scenario visibility configurations for all built-in slots. You can override the default configuration using registerSlotConfig:.

Custom development

Slot protocol (SlotProtocol)

All slots must conform to the SlotProtocol. This protocol defines the minimum lifecycle contract for a slot.

@protocol SlotProtocol <NSObject>

#pragma mark - View Lifecycle

/// Called when the slot is attached to the host.
- (void)onAttach:(id<SlotHost>)host;

/// Called when the slot is detached from the host.
- (void)onDetach;

#pragma mark - Data Lifecycle

/// Data binding callback.
- (void)onBindData:(AliPlayerModel *)model;

/// Data unbinding callback.
- (void)onUnbindData;

@end

SlotProvider is a block type for building slot views.

typedef UIView<SlotProtocol> * _Nullable (^SlotProvider)(UIView *parentView);

Dual lifecycle

Slots use independent View and Data lifecycles.

Lifecycle

Callback method

Timing

Responsibility

Start View

onAttach:

Triggered by playerView.attach:

Establish host connection, subscribe to notifications, and initialize the view.

Data Start

onBindData:

After playback data is set with controller.configure:

Bind business data, such as thumbnails and titles.

Data End

onUnbindData

Before playback data is cleared or updated.

Clean up data-related resources.

View End

onDetach

When playerView.detach is called or the slot is removed.

Release all resources and disconnect all connections.

┌─────────────────── Complete Lifecycle ───────────────────┐
│                                                      │
│   ① onAttach:         ─── View Lifecycle Start          │
│       ↓ Access host, subscribe to notifications, initialize subviews. │
│                                                      │
│   ② onBindData:       ─── Data Lifecycle Start          │
│       ↓ Load thumbnail, set title, configure scene behavior. │
│                                                      │
│   ③ onUnbindData      ─── Data Lifecycle End            │
│       ↓ Clear image cache, reset UI state.              │
│                                                      │
│   ④ onDetach          ─── View Lifecycle End            │
│       ↓ Unsubscribe from notifications, remove timers, release all resources. │
│                                                      │
└──────────────────────────────────────────────────────┘

Inherit from BaseSlot (recommended)

BaseSlot is the recommended base class for all UI slots. It encapsulates common logic such as lifecycle management, notification subscription, and scenario adaptation.

Core properties:

Property

Type

Description

host

id<SlotHost> (weak, readonly)

The host to which the current slot is attached.

slotType

SlotType

The type identifier for the current slot. It is injected by SlotHostLayout during construction.

safeAreaEdges

SlotSafeAreaEdge

The edges of the security zone to avoid. The default is SlotSafeAreaEdgeAll.

deferContentCreation

BOOL

A switch to defer content creation.

contentReady

BOOL (readonly)

Indicates whether the content has been created.

touchPassthrough

BOOL

A switch for touch pass-through. The default is YES.

Core methods:

Method

Description

setupContentView

Subclasses override this method to create custom UI elements.

show / hide

Controls visibility.

showWithAnimation: / hideWithAnimation:

Controls visibility with an animation.

isShowing

Queries the current visibility state.

dismiss

Removes the slot through the host to ensure correct lifecycle management.

ensureContentReady

Ensures that deferred content has been created (idempotent).

currentSceneType

Safely reads the current scene type.

onRegisterElements

Subclasses override this method to declare supported elements and their default visibility.

isElementVisible:

Queries the final visibility of a specified element.

Security zone avoidance (SlotSafeAreaEdge)

typedef NS_OPTIONS(NSUInteger, SlotSafeAreaEdge) {
    SlotSafeAreaEdgeNone   = 0,
    SlotSafeAreaEdgeTop    = 1 << 0,
    SlotSafeAreaEdgeLeft   = 1 << 1,
    SlotSafeAreaEdgeBottom = 1 << 2,
    SlotSafeAreaEdgeRight  = 1 << 3,
    SlotSafeAreaEdgeAll    = SlotSafeAreaEdgeTop | SlotSafeAreaEdgeLeft | SlotSafeAreaEdgeBottom | SlotSafeAreaEdgeRight,
};

In layoutSubviews, SlotHostLayout shrinks the frame of the corresponding edge based on safeAreaEdges. This allows the internal layout of the slot to avoid areas such as the notch or the Home Indicator by directly using its own anchors. Subclasses can set this property in initWithFrame:.

Deferred content creation (deferContentCreation)

When set to YES, onAttach: does not call setupContentView. The content will be created the first time show or ensureContentReady is called. This is suitable for infrequently used slots, such as SettingMenu, to avoid creating unnecessary views during initialization.

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.deferContentCreation = YES;
    }
    return self;
}

Auto-hide delay constant:

FOUNDATION_EXPORT const NSTimeInterval SlotAutoHideDelay;

This constant controls the delay time in seconds before auto-hiding slots such as TopBar and BottomBar after a period of no interaction.

Complete example of a custom slot

  1. Create a custom slot class that inherits from BaseSlot.

    @interface MyCustomCoverSlot : BaseSlot
    
    @property (nonatomic, strong) UIImageView *coverImageView;
    @property (nonatomic, strong) UILabel *titleLabel;
    
    @end
    
    @implementation MyCustomCoverSlot
    
    - (instancetype)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
            // Optional: Configure security zone avoidance.
            self.safeAreaEdges = SlotSafeAreaEdgeNone;
        }
        return self;
    }
    
    #pragma mark - Content Creation
    
    - (void)setupContentView {
        _coverImageView = [[UIImageView alloc] init];
        _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
        _coverImageView.clipsToBounds = YES;
        [self addSubview:_coverImageView];
    
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [self addSubview:_titleLabel];
    }
    
    #pragma mark - Lifecycle
    
    - (void)onAttach:(id<SlotHost>)host {
        [super onAttach:host];
    }
    
    - (void)onBindData:(AliPlayerModel *)model {
        [super onBindData:model];
        if (model.coverUrl) {
            [_coverImageView sd_setImageWithURL:[NSURL URLWithString:model.coverUrl]];
        }
        _titleLabel.text = model.videoTitle;
        [self show];
    }
    
    - (void)onUnbindData {
        _coverImageView.image = nil;
        _titleLabel.text = nil;
        [super onUnbindData];
    }
    
    - (void)onDetach {
        [super onDetach];
    }
    
    #pragma mark - PlayerNotificationDelegate
    
    - (void)playerDidRenderFirstFrame {
        [self hideWithAnimation:YES];
    }
    
    - (void)playerDidChangeState:(PlayerState)state {
        if (state == PlayerStateError) {
            [self show];
        }
    }
    
    #pragma mark - Layout
    
    - (void)layoutSubviews {
        [super layoutSubviews];
        _coverImageView.frame = self.bounds;
        _titleLabel.frame = CGRectMake(16, self.bounds.size.height - 50,
                                       self.bounds.size.width - 32, 30);
    }
    
    @end
    Note

    BaseSlot conforms to the PlayerNotificationDelegate protocol. It automatically registers as the controller's notification delegate when onAttach: is called. Subclasses can directly implement the callback methods they are interested in to receive player events, without having to manually subscribe.

  2. Registration and usage:

    SlotManager *slotManager = playerView.slotManager;
    [slotManager registerSlotType:SlotTypeCover provider:^UIView<SlotProtocol> *(UIView *parentView) {
        return [[MyCustomCoverSlot alloc] initWithFrame:parentView.bounds];
    }];
    [controller configure:model];
    [playerView attach:controller];

Element-level visibility declaration

Subclasses can use onRegisterElements to declare supported elements and their default visibility.

@implementation MyCustomTopBarSlot

- (NSUInteger)onRegisterElements {
    // Return the bitmask of default visible elements.
    // Back and Title are visible by default. Download and Snapshot are hidden by default.
    return TopBarElementBack | TopBarElementTitle;
}

- (void)setupContentView {
    // Decide whether to create the UI based on element visibility.
    if ([self isElementVisible:TopBarElementBack]) {
        // Create the back button.
    }
    if ([self isElementVisible:TopBarElementDownload]) {
        // Create the download button (hidden by default, but can be enabled externally with showElements).
    }
}

@end

The merge logic for isElementVisible: is as follows:

  • If hideElements:forSlot: is called externally, the element is hidden.

  • If showElements:forSlot: is called externally, the element is shown.

  • If there is no external override, the default value declared by onRegisterElements is used.

Custom slot type (CustomSlotType)

In addition to the built-in slot types, you can use CustomSlotType to insert a custom slot at any position.

// 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];
}];

// Check if the custom slot is registered.
BOOL registered = [playerView.slotManager isCustomSlotRegistered:type];

// Get all registered custom slot types.
NSArray<CustomSlotType *> *types = [playerView.slotManager customSlotTypes];

// Unregister the custom slot.
[playerView.slotManager unregisterCustomSlotType:type];
Note

CustomSlotType is defined by a key (unique identifier) and an order (sort value). Equality is based only on the key. The same key cannot be registered more than once. When rebuildSlots is called, custom slots are sorted along with built-in slots based on their order.

Send commands in a slot

Slots send commands to the controller through host.controller. This implements a unidirectional data flow.

// Toggle between play and pause.
- (void)onPlayPauseButtonTapped {
    AliPlayerController *controller = self.host.controller;
    if (controller.playerState == PlayerStatePlaying) {
        [controller pause];
    } else {
        [controller play];
    }
}

// Seek to a position.
- (void)onSeekBarValueChanged:(UISlider *)slider {
    long position = (long)(slider.value * self.host.playerStateStore.duration);
    [self.host.controller seekTo:position];
}

// Toggle full screen.
- (void)onFullscreenButtonTapped {
    BOOL isFullscreen = self.host.viewState.isFullscreen;
    [self.host.controller setFullscreen:!isFullscreen];
}

SlotBehavior (Composition pattern)

SlotBehavior uses a composition pattern design. It allows non-UIView objects to obtain slot capabilities, such as lifecycle management and event subscription. This is useful for scenarios where pure logic components need to listen for player events.

@interface MyAnalyticsTracker : NSObject <PlayerNotificationDelegate>

@property (nonatomic, strong) SlotBehavior *behavior;

@end

@implementation MyAnalyticsTracker

- (instancetype)init {
    self = [super init];
    if (self) {
        _behavior = [[SlotBehavior alloc] init];
    }
    return self;
}

- (void)attachToHost:(id<SlotHost>)host {
    [self.behavior attachToHost:host];
    // Register the notification delegate through the behavior. It will be automatically unsubscribed on detach.
    [self.behavior addNotificationDelegate:self toController:host.controller];
}

- (void)detach {
    [self.behavior detach];
}

#pragma mark - PlayerNotificationDelegate

- (void)playerDidRenderFirstFrame {
    // Report the first frame rendering event.
}

- (void)playerDidEncounterError:(NSError *)error {
    // Report the playback error.
}

@end

Core advantage: All delegates registered through addNotificationDelegate:toController: are automatically unregistered when detach is called. This avoids memory leaks that can be caused by manually managing subscription lifecycles.

Host protocol (SlotHost)

The SlotHost protocol is conformed to by SlotHostLayout (an internal implementation). It provides slots with access to the context.

Method/Property

Description

hostView

Returns the host container view.

model

Gets the current player model.

controller

Gets the player controller (weak reference).

playerStateStore

Gets the player state store (read-only).

viewState

Gets the view layer state, such as full screen and control bar visibility.

sceneType

Gets the current scene type.

setRenderView:

Sets the rendering view for the player. This is called by PlayerSurfaceSlot.

dismissSlotView:

Dismisses the slot view to ensure consistent lifecycle management.

allSlotViews

Returns all attached slot views.

slotViewForType:

Gets an attached slot view by type (O(1) lookup).

slotManager

Gets the slot manager. This is used for element visibility queries.

notifyBackPressed

Notifies the host that the back button was pressed (in non-full screen state).

Note

A slot should read the scenario type through host.sceneType or BaseSlot.currentSceneType. Do not access it through the host.model.sceneType chain. This avoids returning the implicit default value of SceneTypeVOD(0) if the model has not yet been bound.

Default slot factory (DefaultSlotFactory)

DefaultSlotFactory provides centralized management for the default registration of all built-in slots.

Class method

Description

+defaultProviders

Returns a dictionary that maps SlotType → SlotProvider factory closures.

+defaultConfigs

Returns an array of scene visibility configurations for built-in slots (an array of SlotConfig objects).

When SlotManager is initialized, it pulls these two sets of data to complete the default registration. To add or remove a built-in slot, you only need to modify DefaultSlotFactory. You can use SlotManager.clearAll to clear all configurations and re-register the default values.

Technical principles

Slot selection strategy

Request to create a slot → Is the type in the custom registry?
                  ├── Yes → Use custom implementation.
                  └── No → Is the type in the default registry?
                              ├── Yes → Use default implementation.
                              └── No → Skip (do not create).

Unidirectional data flow

The Slot System uses a unidirectional data flow architecture. Slots do not directly hold a reference to the controller.

Controller → State / Event → Slot (State flows down, read-only)
Slot → Command → Controller (Commands flow up, send-only)
  • State flows down: State is actively queried through host.playerStateStore or passively received through PlayerNotificationDelegate callbacks.

  • Commands flow up: Playback commands are invoked through host.controller and executed by the controller.

Isolation between slots

Slots are strictly forbidden from directly retrieving instances of other slots or communicating peer-to-peer. When one slot needs to affect another:

  1. The initiating slot sends a state change through host.controller.

  2. The Controller notifies all slots that are observing this change through PlayerNotificationDelegate.

This 'event up, state down' flow avoids a mesh of UI coupling.

Bottom control bar differences by scene

Control

VOD

LIVE

VIDEO_LIST

RESTRICTED

MINIMAL

Play/pause button

✓

✓

✓

✓

✗

Progress bar

Draggable

Not draggable

Draggable

Not draggable

✗

Time display

✓

✓

✓

✓

✗

Refresh button

✗

✓

✗

✗

✗

Full screen button

✓

✓

✓

✓

✗

API quick reference

Core protocols and classes

Class/Protocol

Description

SlotProtocol

The slot protocol, which defines the minimum lifecycle contract.

BaseSlot

The base class for slots, which encapsulates common logic.

SlotManager

The slot manager, which provides centralized registration, visibility control, and runtime access.

SlotHost

The host protocol, which provides context access.

SlotHostLayout

The internal implementation of the host protocol (a UIView subclass).

SlotConfig

Configuration for scene visibility.

SlotBehavior

A composition pattern behavior class that provides slot capabilities to non-UIView objects.

DefaultSlotFactory

The default slot factory, which provides centralized management for built-in slot registration.

CustomSlotType

A custom slot type that supports insertion between built-in slots.

SlotType

An enumeration of built-in slot types.

SlotManager method quick reference

Category

Method

Description

Slot registration

registerSlotType:provider:

Registers or overwrites a built-in slot provider.

unregisterSlotType:

Unregisters a slot of a specified type.

isRegistered:

Check the registration status

Custom slots

registerCustomSlotType:provider:

Registers a custom slot.

unregisterCustomSlotType:

Unregisters a custom slot.

isCustomSlotRegistered:

Checks if a custom slot is registered.

customSlotTypes

Gets all registered custom slot types.

Slot visibility

hideSlot: / showSlot:

Hides or shows a slot.

isSlotHidden:

Checks if a slot is hidden.

Scene visibility

registerSlotConfig:

Configuring Registration Scenario Visibility

unregisterSlotConfigForType:

Removes a scene visibility configuration.

slotConfigForType:

Gets a scene visibility configuration.

Element visibility

hideElements:forSlot:

Hides specific elements within a slot.

showElements:forSlot:

Shows specific elements within a slot.

setHiddenElementMask:forSlot:

Replaces the hidden element mask.

hiddenElementMaskForSlot:

Gets the hidden element mask.

shownElementMaskForSlot:

Gets the shown element mask.

setAllHiddenElementMasks:

Batch sets all hidden element masks.

clearAllElementMasks

Clears all element visibility configurations.

Runtime

slotViewForType:

Gets an attached slot view.

rebuildSlots

Rebuilds all slots.

clearAll

Clears configurations and re-registers default values.

Example reference

The PlayerKitUsages/UsageSlotSystem module provides a complete usage example for the Slot System. It demonstrates the out-of-the-box use of default slot configurations, custom slot registration and hiding using SlotManager, and the automatic management of the slot lifecycle.