buildCoverImageSlot function
构建封面图插槽的默认实现。 Builds the default cover image slot content.
监听封面 URL 和渲染状态,在播放器首帧渲染完成前显示封面图。 Listens to cover URL and render state; displays the cover image until the player has rendered its first frame.
Implementation
Widget buildCoverImageSlot(
SlotBuildContext ctx,
double width,
double height,
) {
return ListenableBuilder(
listenable: Listenable.merge([
ctx.controller.coverURLNotifier,
ctx.controller.isRenderedNotifier,
]),
builder: (buildContext, widget) {
final coverUrl = ctx.controller.coverURLNotifier.value;
final isRendered = ctx.controller.isRenderedNotifier.value;
// 已渲染完成,或者没有封面,都不显示封面
if (isRendered || coverUrl == null || coverUrl.isEmpty) {
return const SizedBox.shrink();
}
return CoverImageWidget(
imageUrl: coverUrl,
width: width,
height: height,
fit: BoxFit.cover,
);
},
);
}