情境類型 (SceneType) 是 AliPlayerKit 的播放情境抽象機制,通過指定不同情境自動適配 UI 行為、手勢控制和插槽可見度。
普通點播情境無需設定 SceneType,預設即為 SceneTypeVOD,具備完整的播放能力。只有在直播、受限播放等非點播情境時,才需要顯式指定。
概念介紹
什麼是 SceneType?
SceneType 是告知播放器當前運行在什麼業務情境中的枚舉標識。設定 SceneType 後,AliPlayerKit 會自動:
調整插槽可見度(如直播情境隱藏封面圖)。
過濾手勢行為(如直播/受限情境禁用進度拖拽和倍速,視頻列表情境禁用垂直手勢)。
適配功能限制(如受限情境確保使用者按序完整觀看)。
開發人員只需設定一個枚舉值,架構自動完成上述適配,極大降低不同業務情境的定製成本。
核心價值
價值 | 說明 |
零配置適配 | 設定情境後,UI 與互動行為自動調整,無需逐個配置插槽和手勢 |
一致性保證 | 同一情境下所有播放器執行個體保持統一的 UI 規範和互動行為 |
降低定製成本 | 用一行代碼替代數十行插槽可見度 + 手勢過濾代碼 |
可擴充性 | 可通過 SlotConfig 和 GestureControlSlotConfig 進一步微調 |
功能特性
情境概覽
AliPlayerKit 內建 5 種情境類型,覆蓋絕大多數播放業務:
情境 | 枚舉值 | 說明 | 適用業務 | 與 VOD 的差異 |
點播 |
| 預設情境,支援全部控制能力 | 常規點播、課程、媒體庫 | — |
直播 |
| 即時資料流無固定時間長度,自動禁用時間軸操作 | 直播、賽事、電商直播 | 禁用進度拖拽/倍速;隱藏封面圖 |
視頻列表 |
| 禁用垂直手勢,避免與列表滾動衝突 | 資訊流、短視頻列表 | 禁用音量/亮度垂直手勢 |
受限播放 |
| 防跳播,確保使用者完整觀看 | 考試監控、培訓課程 | 禁用進度拖拽/倍速;隱藏封面圖 |
極簡模式 |
| 純淨畫面,所有控制需自行實現 | 背景播放、完全自訂 UI | 隱藏所有控制組件和手勢 |
枚舉定義
// SceneType.h
typedef NS_ENUM(NSInteger, SceneType) {
/** ApsaraVideo for VOD情境(預設) */
SceneTypeVOD = 0,
/** 直播情境 */
SceneTypeLive = 1,
/** 視頻列表或短視頻流情境 */
SceneTypeVideoList = 2,
/** 受限播放情境 */
SceneTypeRestricted = 3,
/** 極簡播放頁情境 */
SceneTypeMinimal = 4,
};情境能力矩陣
插槽可見度
插槽系統根據情境類型自動控制組件可見度。以下矩陣反映 DefaultSlotFactory.defaultConfigs 的預設規則:
插槽 | VOD | Live | VideoList | Restricted | Minimal |
PlayerSurface | ✓ | ✓ | ✓ | ✓ | ✓ |
GestureControl | ✓ | ✓ | ✓ | ✓ | ✗ |
LandscapeHint | ✓ | ✓ | ✓ | ✓ | ✗ |
Cover | ✓ | ✗ | ✓ | ✗ | ✗ |
CenterDisplay | ✓ | ✓ | ✓ | ✓ | ✗ |
PlayState | ✓ | ✓ | ✓ | ✓ | ✓ |
LogPanel | ✓ | ✓ | ✓ | ✓ | ✗ |
TopBar | ✓ | ✓ | ✓ | ✓ | ✗ |
BottomBar | ✓ | ✓ | ✓ | ✓ | ✗ |
SettingMenu | ✓ | ✓ | ✓ | ✓ | ✗ |
OptionPanel | ✓ | ✓ | ✓ | ✓ | ✗ |
可見度規則說明:
PlayerSurface和PlayState:所有情境可見(無excludedScenes配置)。Cover:在Live、Restricted、Minimal情境中不可見。其餘插槽(
GestureControl、LandscapeHint、CenterDisplay、LogPanel、TopBar、BottomBar、SettingMenu、OptionPanel):僅在Minimal情境中不可見。
手勢行為差異
GestureControlSlot 內部根據 currentSceneType 在各手勢處理方法中進行情境過濾:
手勢 | VOD | Live | VideoList | Restricted | Minimal |
單擊(顯示/隱藏控制欄) | ✓ | ✓ | ✓ | ✓ | ✗ |
雙擊(播放/暫停) | ✓ | ✓ | ✓ | ✓ | ✗ |
長按(倍速播放) | ✓ | ✗ | ✓ | ✗ | ✗ |
水平拖動(進度跳轉) | ✓ | ✗ | ✓ | ✗ | ✗ |
左側垂直拖動(亮度) | ✓ | ✓ | ✗ | ✓ | ✗ |
右側垂直拖動(音量) | ✓ | ✓ | ✗ | ✓ | ✗ |
過濾邏輯說明:
Minimal:所有手勢的處理方法入口處直接
return(handleSingleTap:/handleDoubleTap:/handleLongPress:/handlePan:)。Live / Restricted:長按和水平拖動被過濾(
handleLongPress:和tryStartDragWithCurrentPoint:中檢查)。VideoList:垂直拖動被過濾(
tryStartDragWithCurrentPoint:中檢查SceneTypeVideoList時直接return)。
使用方式
基本用法
情境類型通過 AliPlayerModel.sceneType 屬性指定。預設為 SceneTypeVOD,無需顯式設定。
點播情境(預設,無需設定):
VideoSource *source = [VideoSource urlSourceWithUrl:@"https://example.com/video.mp4"];
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
// model.sceneType 預設為 SceneTypeVOD,無需設定
[controller configure:model];直播情境:
VideoSource *source = [VideoSource urlSourceWithUrl:@"https://live.example.com/stream.m3u8"];
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeLive;
model.videoTitle = @"直播間";
[controller configure:model];視頻列表情境:
VideoSource *source = [VideoSource urlSourceWithUrl:videoUrl];
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeVideoList;
[controller configure:model];各情境詳細說明
VOD - 點播情境(預設)
適用情境:常規視頻播放、線上課程、媒體庫瀏覽等。
能力說明:
支援全部 11 種預設插槽
支援全部 6 種手勢
支援進度拖拽、倍速播放、清晰度切換
支援全屏切換
// 無需顯式指定 SceneType,預設即為 VOD
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.coverUrl = @"https://example.com/cover.jpg";
model.videoTitle = @"精彩視頻";
model.autoPlay = YES;
[controller configure:model];Live - 直播情境
適用情境:即時直播、賽事直播、電商直播等。
與 VOD 的關鍵差異:
禁用:進度拖拽(水平手勢)、倍速播放(長按手勢)(因為直播無固定時間長度)
隱藏:封面圖插槽(直播流無需封面)
保留:單擊/雙擊手勢、音量/亮度調節
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:liveSource];
model.sceneType = SceneTypeLive;
model.videoTitle = @"熱門直播";
model.autoPlay = YES;
[controller configure:model];VideoList - 視頻列表情境
適用情境:資訊流中的內嵌視頻、短視頻列表、可滑動視頻集合等。
與 VOD 的關鍵差異:
禁用:左側/右側垂直拖動手勢(避免與列表
UIScrollView滑動衝突)保留:其餘所有功能(進度拖拽、倍速、單擊/雙擊/長按等)
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeVideoList;
model.autoPlay = YES;
[controller configure:model];Restricted - 受限播放情境
適用情境:線上考試監控視頻、培訓認證課程、著作權保護情境等。
與 VOD 的關鍵差異:
禁用:進度拖拽(水平手勢)、倍速播放(長按手勢)(確保使用者按序完整觀看)
隱藏:封面圖插槽
保留:單擊/雙擊手勢、音量/亮度調節
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeRestricted;
model.videoTitle = @"安全培訓課程";
model.autoPlay = YES;
// 通常配合禁止截屏
model.disableScreenshot = YES;
[controller configure:model];Minimal - 極簡模式
適用情境:背景播放、完全自訂 UI、預覽縮圖播放等。
與 VOD 的關鍵差異:
隱藏:幾乎所有 UI 控制插槽(僅保留
PlayerSurface和PlayState)禁用:所有手勢(
GestureControl插槽在 Minimal 情境不可見,且內部手勢處理方法均會直接return)適用:需要完全自訂播放控制 UI 的情境
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeMinimal;
[controller configure:model];
// 所有控制需要自行通過 controller 的 API 實現
// 例如:[controller play]; [controller pause]; [controller seekTo:position];自訂開發
插槽可見度微調
當情境預設的插槽可見度不完全滿足需求時,可通過 SlotConfig 進行微調:
// 樣本:在 Live 情境下額外隱藏 TopBar
SlotConfig *topBarConfig = [SlotConfig configWithSlotType:SlotTypeTopBar
excludedScenes:[NSSet setWithObjects:
@(SceneTypeMinimal),
@(SceneTypeLive), nil]];
// 註冊到 SlotManager(覆蓋該插槽類型的預設 SlotConfig)
[playerView.slotManager registerSlotConfig:topBarConfig];也可以通過 hideSlot: 直接隱藏整個插槽,不依賴情境判斷:
// 無條件隱藏 TopBar(需調用 rebuildSlots 生效)
[playerView.slotManager hideSlot:SlotTypeTopBar];registerSlotConfig: 為情境級可見度控制,hideSlot: 為插槽級可見度控制。兩者獨立生效,插槽需同時通過兩項檢查才會被構建。
手勢行為微調
手勢控制支援兩種微調方式:
方式一:通過 SlotManager 的元素位元遮罩 API 禁用特定手勢(推薦,在 attach 前配置即可):
// 在 VOD 情境下禁用長按倍速
[playerView.slotManager hideElements:GestureElementLongPress
forSlot:SlotTypeGestureControl];方式二:通過 GestureControlSlotConfig 直接控制(需在 attach 後擷取插槽執行個體):
// 擷取手勢控制插槽執行個體
GestureControlSlot *gestureSlot = (GestureControlSlot *)[playerView.slotManager slotViewForType:SlotTypeGestureControl];
// 修改配置(立即生效)
GestureControlSlotConfig *config = [GestureControlSlotConfig defaultConfig];
config.longPressEnabled = NO;
config.horizontalDragEnabled = NO;
gestureSlot.config = config;兩種方式獨立生效。元素位元遮罩在插槽構建時應用(setupContentView 階段),GestureControlSlotConfig 在運行時動態生效。
在Minimal情境下註冊自訂插槽
在 Minimal 情境下,大多數預設插槽被情境配置排除。如需恢複某個插槽,可覆蓋其 SlotConfig:
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeMinimal;
// 覆蓋 BottomBar 的情境配置,移除 Minimal 排除規則
[playerView.slotManager registerSlotConfig:
[SlotConfig configWithSlotType:SlotTypeBottomBar]]; // 無 excludedScenes = 所有情境可見
[controller configure:model];動態可見度條件
使用 SlotConfig 的 visibilityCondition 回調實現運行時動態控制:
SlotConfig *coverConfig = [SlotConfig configWithSlotType:SlotTypeCover
excludedScenes:nil
visibilityCondition:^BOOL{
// 僅在有封面 URL 時顯示封面插槽
return model.coverUrl != nil;
}];
[playerView.slotManager registerSlotConfig:coverConfig];isVisibleInScene: 先檢查 excludedScenes(命中則不可見),再檢查 visibilityCondition(返回 NO 則不可見),兩者都通過才可見。
情境選擇指南
決策流程
需要播放器控制 UI 嗎?
├── 否 → SceneTypeMinimal
└── 是 → 是直播流嗎?
├── 是 → SceneTypeLive
└── 否 → 播放器嵌入可滾動列表中嗎?
├── 是 → SceneTypeVideoList
└── 否 → 需要防止使用者跳播嗎?
├── 是 → SceneTypeRestricted
└── 否 → SceneTypeVOD(預設)情境選擇匯總表
業務需求 | 推薦情境 | 關鍵理由 |
常規視頻播放 |
| 預設情境,全功能支援 |
直播/賽事即時資料流 |
| 自動禁用無意義的進度操作 |
UIScrollView 嵌入視頻 |
| 自動規避垂直手勢衝突 |
培訓/考試/著作權保護 |
| 自動禁止跳播和倍速 |
完全自訂 UI |
| 純淨畫布,零內建 UI 幹擾 |
後台/畫中畫播放 |
| 無需 UI 控制組件 |
API 速查
SceneType枚舉
枚舉值 | 整數值 | 說明 |
| 0 | ApsaraVideo for VOD情境(預設) |
| 1 | 直播情境 |
| 2 | 視頻列表/短視頻流情境 |
| 3 | 受限播放情境 |
| 4 | 極簡播放頁情境 |
SlotConfig
方法 / 屬性 | 說明 |
| 建立無情境排除的配置(所有情境可見) |
| 建立指定情境排除的配置 |
| 建立帶情境排除和動態條件的配置 |
| 插槽類型( |
| 排除的情境集合, |
| 動態可見度條件 Block( |
| 判斷插槽在指定情境中是否可見 |
GestureControlSlotConfig
屬性 | 類型 | 預設值 | 說明 |
|
|
| 是否啟用單擊手勢 |
|
|
| 是否啟用雙擊手勢 |
|
|
| 是否啟用長按手勢 |
|
|
| 是否啟用水平拖動手勢 |
|
|
| 是否啟用左側垂直拖動手勢 |
|
|
| 是否啟用右側垂直拖動手勢 |
| 類方法 | — | 建立所有手勢均啟用的預設配置 |
SlotManager情境相關API
方法 | 說明 |
| 為插槽類型註冊情境可見度配置(覆蓋預設配置) |
| 移除指定插槽類型的情境配置(移除後預設可見) |
| 擷取指定插槽類型的情境可見度配置 |
| 隱藏指定插槽(插槽級,獨立於情境配置) |
| 顯示之前隱藏的插槽 |
| 按位元遮罩隱藏插槽內元素 / 禁用手勢 |
| 按位元遮罩顯示插槽內元素 / 啟用手勢 |
| 擷取已掛載的插槽視圖執行個體 |
| 重建所有插槽(情境配置變更後需調用) |
相關檔案
檔案 | 說明 |
| SceneType 枚舉定義 |
| 情境類型設定入口( |
| 插槽可見度配置 |
| 預設插槽 Provider 和情境可見度規則 |
| 插槽系統統一管理入口 |
| 手勢元素位元遮罩定義 |
| 手勢控制插槽及 |
| 插槽基類( |
完整API詳見API參考。
最佳實務
注意事項
事項 | 說明 |
建立時確定 | SceneType 在 |
列表情境優先 | 當播放器嵌入 |
Minimal 需自行控制 | 選擇 Minimal 後所有播放控制需開發人員通過 |
可組合微調 | 當預設行為不完全滿足需求時,可通過 |
Live 與 Restricted 行為一致 | 兩者的手勢過濾規則相同(禁用進度拖拽和倍速),差異僅在封面圖可見度(兩者都隱藏)和業務語義 |
常見問題
VOD 和 VideoList 的區別是什嗎?
主要區別在於垂直手勢:SceneTypeVideoList 禁用音量/亮度垂直手勢,避免與列表容器滾動手勢衝突。其餘功能與 VOD 一致。
Minimal情境下如何?自訂控制?
通過 AliPlayerController 的 API 直接控制播允許存取為,並可註冊自訂插槽覆蓋 UI:
AliPlayerModel *model = [[AliPlayerModel alloc] initWithVideoSource:source];
model.sceneType = SceneTypeMinimal;
[controller configure:model];
// 通過 controller API 直接控制
[controller play];
[controller pause];
[controller seekTo:30000]; // 跳到 30 秒如何在Live情境下恢複進度拖拽?
如果你的直播情境支援回看(timeshift),可通過 SlotManager 的元素控制 API 恢複被禁用的手勢:
// 恢複水平拖動手勢(進度跳轉)
[playerView.slotManager showElements:GestureElementHorizontalDrag
forSlot:SlotTypeGestureControl];此方式僅恢複元素級可見度。GestureControlSlot 內部的情境過濾邏輯是硬式編碼,showElements: 無法繞過。如需完全自訂手勢行為,建議通過 GestureControlSlotConfig 或替換 GestureControlSlot 實現。