🎬 短剧模块
2.0: 对应 2.0.0 纯短剧契约。pub.dev 当前仍提供 1.0.3;依赖尚未升级时请切换到 1.x 文档。
SDK 管理解锁
播放器是全屏原生页面,应获得稳定的可用视口。Android 宿主必须继承 FlutterFragmentActivity;iOS 会按 PlatformView 的有效 bounds 创建并更新播放控制器尺寸。
自建列表、分类、搜索、历史或卡片进入播放页时,使用 SDK 实时返回的完整 DramaInfo 创建配置:
DramaPlayerNativeView(
config: DramaPlayerConfig.forDrama(
drama: drama,
source: DramaPlayerEntrySource.search,
detail: const DramaDetailConfig(
unlockMode: DramaUnlockMode.sdkManaged,
freeEpisodes: 5,
unlockEpisodesPerAd: 2,
),
),
)forDrama 使用 drama.index 作为起播集数,并保留厂商返回的完整入口上下文。 Android 会继续传递推荐 recMap、入口来源和 fromGid;iOS 会设置 entranceType、infoModel 和 groupId。可用来源包括 direct、home、 skitMixed、history、card 和 search。不要把实时查询结果压缩成单独的 短剧 ID 后再打开播放器,否则会丢失历史进度和推荐归因。
只有宿主本来就只有短剧 ID、没有任何 SDK 返回的入口数据时,才直接构建:
DramaPlayerNativeView(
config: const DramaPlayerConfig(
dramaId: 1001,
episode: 1,
detail: DramaDetailConfig(
unlockMode: DramaUnlockMode.sdkManaged,
freeEpisodes: 5,
unlockEpisodesPerAd: 2,
),
),
)每个激励广告最多解锁 10 集。SDK 管理模式会自行请求、展示并校验穿山甲广告。
宿主管理解锁
DramaPlayerNativeView(
config: const DramaPlayerConfig(
dramaId: 1001,
episode: 1,
detail: DramaDetailConfig(
unlockMode: DramaUnlockMode.hostManaged,
freeEpisodes: 5,
unlockEpisodesPerAd: 2,
),
),
listener: DramaPlayerListener(
onUnlockRequested: (session) async {
await session.accept(unlockEpisodes: 2);
final ad = await GromoreAds.loadRewarded(
RewardedAdRequest(placementId: 'your_reward_placement'),
);
final outcome = GromoreAds.events.firstWhere(
(event) =>
event.requestId == ad.requestId &&
(event.type == AdEventType.rewarded ||
event.type == AdEventType.rewardFailed ||
event.type == AdEventType.failed ||
event.type == AdEventType.closed),
);
try {
await session.adWillShow();
await ad.show();
final event = await outcome;
final reward = event.reward;
if (event.type == AdEventType.rewarded && reward?.verified == true) {
await session.rewardVerified(
rewardName: reward?.name,
rewardAmount: reward?.amount,
ecpm: event.ecpm?.ecpm?.toString(),
);
} else {
await session.cancel();
}
} catch (_) {
if (!session.isClosed) await session.cancel();
rethrow;
} finally {
await ad.dispose();
}
},
),
)宿主管理模式必须展示穿山甲或 GroMore 激励广告。顺序固定为 accept、adWillShow、rewardVerified;一个 session 只能终结一次,页面销毁或超时后继续调用会抛状态错误。
播放事件
DramaPlayerListener 提供请求、开始、暂停、继续、完成、页面切换、广告请求/填充/展示/点击/奖励、解锁开始与结束事件。所有事件携带 view ID;厂商新增事件以 unknown 类型和原始数据保留。