Story Block

For android:

StoryBlock is a heavy object containing multiple instances of the player, Heavy-lifting UI elements, and intensive background tasks, Beware that the recommended number of the StoryBlock being used in a single screen is 1. However, in a wide range of new Android devices, 2 instances might work alright. Any number of StoryBlock above this limitation is not recommended by the Firework team and is not supported.

Currently, there are five source types of the story block:

  • Discover

  • Channel

  • Playlist

  • Dynamic Content

  • Hashtag Playlist

  • SKU

Integration

import 'package:fw_flutter_sdk/fw_flutter_sdk.dart';
import 'package:visibility_detector/visibility_detector.dart';

StoryBlockController? _storyBlockController;

/// discover
StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
)

/// channel
StoryBlock(
  height: 400,
  source: StoryBlockSource.channel,
  channel: "your encoded channel id",
)

/// playlist
StoryBlock(
  height: 400,
  source: StoryBlockSource.playlist,
  playlist: "your encoded playlist id",
  channel: "your encoded channel id",
)

/// dynamic content
StoryBlock(
  height: 400,
  source: StoryBlockSource.dynamicContent,
  dynamicContentParameters: const {
    '<cohort key>': ['<cohort value1>', '<cohort value2>']
  },
)

/// hashtag playlist
StoryBlock(
  height: 400,
  source: StoryBlockSource.hashtagPlaylist,
  channel: "your encoded channel id",
  hashtagFilterExpression: "<hashtag filter expression>",
)

/// sku
StoryBlock(
  height: 400,
  source: StoryBlockSource.sku,
  channel: "your encoded channel id",
  productIds: ["prodct_id_1", "prodct_id_2"],
)

/// single content
StoryBlock(
  height: 400,
  source: StoryBlockSource.singleContent,
  contentId="your encoded video or live stream id"
);

Configure corner radius

StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
  cornerRadius: 20,
);

Story block loading result callback

StoryBlock widget provides onStoryBlockLoadFinished property for setting story block loading result callback.

StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
);

Story block empty callback

StoryBlock widget provides onStoryBlockEmpty property for setting story block empty callback. The callback is triggered when there are no items in the story block. For example, you could hide the widget when the callback is triggered. The callback is triggered in the following scenarios:

  1. Load successfully but the back end returns an empty list

  2. The load failed and the list is empty

StoryBlock(
  source: StoryBlock.discover,
  onStoryBlockEmpty: (error) {
    // Hide the widget
  },
);

Story block configuration

StoryBlock widget provides storyBlockConfiguration prop for configuring Video Player. The current configurable properties are showShareButton, shareBaseURL, and ctaWidth etc. Please refer to StoryBlockConfiguration for more details.

final storyBlockConfiguration = StoryBlockConfiguration(
  showShareButton: true,
  ctaWidth: VideoPlayerCTAWidth.compact,
);
StoryBlock(
  source: StoryBlockSource.discover,
  storyBlockConfiguration: storyBlockConfiguration,
);

Show the countdown time for the livestream trailer

final storyBlockConfiguration = StoryBlockConfiguration(
  countdownTimerConfiguration: CountdownTimerConfiguration(
    isHidden: false,
  ),
);
StoryBlock(
  source: StoryBlockSource.discover,
  storyBlockConfiguration: storyBlockConfiguration,
);

Play or pause story block programmatically

StoryBlockController? _storyBlockController;

StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
  onStoryBlockCreated: (controller) {
    _storyBlockController = controller;
  },
);

// Play story block
_storyBlockController?.play();
// Pause story block
_storyBlockController?.pause();

Open fullscreen story block programmatically

StoryBlockController? _storyBlockController;

StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
  onStoryBlockCreated: (controller) {
    _storyBlockController = controller;
  },
);

// Open fullscreen story block
_storyBlockController?.openFullscreen();

Enable PiP(Picture in Picture)

You need to set enablePictureInPicture to true to enable PiP.

StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
  enablePictureInPicture: true,
);

Set up the iOS project

To enable PiP outside the iOS app, you also need to add Background Modes capability via Signing & Capabilities in your iOS project settings. More information about this can be found here: Apple Documentation

To use Picture in Picture, we configure the app to support background audio playback. See Configuring the Audio Playback of iOS and tvOS Apps for more details.

Keep alive when scrolling the widget out of the view box

Generally, if you put the story block widget as the child of ListView, it will be rebuilt when scrolling the widget out of the view box. You could set wantKeepAlive as true to make the story block widget keep alive when scrolling the widget out of the view box.

StoryBlock(
  height: 400,
  source: StoryBlockSource.discover,
  // Keep the widget alive when scrolling the widget out of the view box
  wantKeepAlive: true,
);

Reference

StoryBlock

Last updated