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 StoryBlockViewController

Use FWSStoryBlockView

Use FWSStoryBlockSwiftUIView

Viewport-based autoplay support

By default, autoplay is enabled, and the video begins playing as soon as the component is instantiated. However, when the component is embedded within a ScrollView, TableView, or CollectionView, a more seamless user experience is achieved by initiating autoplay only when the component enters the viewport, and pausing playback when it leaves. This behavior can be implemented setting useSafeAreaViewport as true.

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 additionalViewportExcludedInset, which allows you to exclude additional custom insets. The final viewport is therefore determined by subtracting the combined insets of both the safe area and additionalViewportExcludedInset from the screen bounds.

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?