Story Block (iOS)

Display Story Block

Use FWSStoryBlockView

The FWSStoryBlockView provides a UIView wrapper for the StoryBlockViewController. You can customize the FWSStoryBlockView just like the StoryBlockViewController.

Integration

  1. Import FireworkVideo.

  2. Instantiate FWSStoryBlockView and embed it.

The following are the sample codes:

import UIKit
import FireworkVideo

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.addStoryBlockView()
    }

    func addStoryBlockView() {
        let storyBlockView = FWSStoryBlockView(source: .discover)
        // Please ensure that viewConfiguration and isPictureInPictureEnabled are set
        // before attaching it to the parent view
        storyBlockView.viewConfiguration = getStoryBlockConfiguration()
        storyBlockVC.isPictureInPictureEnabled = true

        storyBlockView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(storyBlockView)

        NSLayoutConstraint.activate([
            storyBlockView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
            storyBlockView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
            storyBlockView.heightAnchor.constraint(equalToConstant: 500),
            storyBlockView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor)
        ])
    }

    func getStoryBlockConfiguration() -> StoryBlockConfiguration {
        var viewConfiguration = StoryBlockConfiguration()
        viewConfiguration.playbackButton.isHidden = false
        viewConfiguration.fullScreenPlayerView.playbackButton.isHidden = false
        return viewConfiguration
    }
}
circle-exclamation

Use FWSStoryBlockSwiftUIView (SwiftUI)

The FWSStoryBlockSwiftUIView provides a SwiftUI View wrapper for the StoryBlockViewController. You can customize the FWSStoryBlockSwiftUIView just like the StoryBlockViewController.

Integration

  1. Import FireworkVideo.

  2. Instantiate FWSStoryBlockSwiftUIView and embed it.

The following are the sample codes:

Story Block Content Source

The enum StoryBlockContentSource defines the different sources that can be used to populate the story block.

Channel

Displays content from the specified channel id.

Channel Playlist

Displays content from the specified playlist id.

Dynamic Content

Displays dynamic content based on the provided channel id and content parameters.

Hashtag Playlist

Displays content based on the provided channel id and the hashtag expression.

Or a more advanced hashtag expression can be used to fine tune the results

SKU Playlist

Displays content based on the provided channel id and SKU/Product external IDs.

Single Video or Live Stream

Displays a single video or live stream content.

Video Ads

Displays video ads based on vast XML.

Channel Videos

Receive story block events

  1. Set the delegate

  1. Conform to StoryBlockViewControllerDelegate protocol

Play and pause StoryBlock programmatically

Use FWSStoryBlockView

Use FWSStoryBlockSwiftUIView

Enter Story Block Fullscreen Programmatically

Use FWSStoryBlockView

Use FWSStoryBlockSwiftUIView

Autoplay

Autoplay lets the story block automatically start playing without requiring user interaction. It is controlled by:

This is the prerequisite for everything below — it is true by default, so autoplay is on out of the box. When and how playback is triggered then depends on whether viewport-based autoplay is turned on (viewport.useSafeAreaViewport).

Container-based autoplay (default)

When viewport.useSafeAreaViewport = false (the default), autoplay is tied to the component's on-screen presence:

  • Autoplay starts when the component is at least partially on screen, and pauses when the component is fully off-screen.

Viewport-based autoplay

When the component is embedded in a ScrollView, TableView, or CollectionView, you can opt into viewport-based autoplay by setting viewport.useSafeAreaViewport = true. In this mode, visibility is measured against the viewport rather than the screen:

  • Autoplay starts when the component's visibility within the viewport is greater than or equal to viewport.threshold, and pauses when it falls below.

  • The viewport itself is customizable via viewport.safeAreaEdges and viewport.additionalViewportExcludedInset (see below).

Customize viewport

The default viewport is defined as the screen bounds minus the safe area insets—such as the status bar, top navigation bar, bottom tab bar, and bottom home indicator.

However, you can further refine this viewport by specifying safeAreaEdges and additionalViewportExcludedInset. Please refer to the following code snippets for more details.

Player configurations

Please refer to Player configurations (iOS).

Story block layout

You can customize the width and height of the story block to achieve either a horizontal or vertical layout.

Vertical layout

As shown in the following code snippets, we set the story block’s width to 350 and height to 533 to achieve a horizontal layout.

Use StoryBlockViewController

Use StoryBlockView

Use StoryBlockSwiftUIView

Horizontal layout

As shown in the following code snippets, we set the story block’s width to 533 and height to 255 to achieve a horizontal layout.

Use StoryBlockViewController

Use StoryBlockView

Use StoryBlockSwiftUIView

Loading indicator color

You can use the following code snippets to customize loading indicator color.

Last updated

Was this helpful?