buildPlayStateSlot function
构建播放状态插槽的默认实现。 Builds the default play state slot content.
监听播放状态、加载状态和错误信息,显示加载中或错误状态的 UI。 Listens to play state, loading state, and error info; displays loading or error state UI.
Implementation
Widget buildPlayStateSlot(
SlotBuildContext ctx,
double width,
double height,
) {
// 监听播放状态、错误码、错误信息等变化
Listenable listenable = Listenable.merge([
ctx.controller.playStateNotifier,
ctx.controller.playErrorNotifier,
ctx.controller.isLoadingStateNotifier,
]);
return ListenableBuilder(
listenable: listenable,
builder: (context, _) {
// 获取播放状态
final playState = ctx.controller.playStateNotifier.value;
final isLoadingState = ctx.controller.isLoadingStateNotifier.value;
if (!playState.shouldBuildErrorWidget) {
if (isLoadingState) {
return PlayStateWidget(
widgetStatus: PlayStatus.loading,
statusCode: PlayerI18n.t(PlayerI18nKeys.statusLoading),
);
} else {
// 如果不需要构建播放状态视图,则返回空组件
return const SizedBox.shrink();
}
}
// 获取错误码和错误信息
final playError = ctx.controller.playErrorNotifier.value;
final errorCode = playError?.keys.firstOrNull;
final errorMsg = playError?.values.firstOrNull;
return PlayStateWidget(
widgetStatus: PlayStatus.error,
statusCode: errorCode?.toString(),
statusMessage: errorMsg,
);
},
);
}