Storyblock (iOS)

Display Story Block

Use StoryBlockViewController

Integration

  1. Import FireworkVideo.

  2. Create a new StoryBlockViewController.

  3. Embed instantiated StoryBlockViewController.

import FireworkVideo

class ViewController: UIViewController {

    func embedFeedInViewController() {
        let storyBlockVC = StoryBlockViewController(source: .discover)
        storyBlockVC.viewConfiguration = getStoryBlockConfiguration()

        self.addChild(feedVC)

        storyBlockVC.view.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(storyBlockVC.view)
        NSLayoutConstraint.activate([
            storyBlockVC.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
            storyBlockVC.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
            storyBlockVC.view.heightAnchor.constraint(equalToConstant: 500),
            storyBlockVC.view.centerYAnchor.constraint(equalTo: self.view.centerYAnchor)
        ])

        storyBlockVC.didMove(toParent: self)
    }

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

Use StoryBlockView

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

Integration

  1. Follow the instruction to install FireworkVideoUI.

  2. Import FireworkVideo and FireworkVideoUI.

  3. Instantiate StoryBlockView and embed it.

The following are the sample codes:

import UIKit
import FireworkVideo
import FireworkVideoUI

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

    func addStoryBlockView() {
        let storyBlockView = StoryBlockView(source: .discover)
        storyBlockView.viewConfiguration = getStoryBlockConfiguration()

        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
    }
}

Use StoryBlockSwiftUIView(SwiftUI)

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

Integration

  1. Follow the instruction to install FireworkVideoUI.

  2. Import FireworkVideo and FireworkVideoUI.

  3. Instantiate StoryBlockSwiftUIView and embed it.

The following are the sample codes:

import SwiftUI
import FireworkVideo
import FireworkVideoUI

struct ContentView: View {
    var body: some View {
        List {
            Spacer()
            StoryBlockSwiftUIView(
                source: .discover,
                viewConfiguration: getStoryBlockConfiguration(),
                isPictureInPictureEnabled: true,
                onStoryBlockLoaded: {
                    debugPrint("Story block loaded successfully.")
                },
                onStoryBlockFailedToLoad: { error in
                    debugPrint("Story block did fail loading.")
                }
            ).frame(height: 500)
            Spacer()
        }
    }

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

Story Block Content Source

The enum StoryBlockContentSource defines the different sources that can be used to populate the story block. The content source must be specified when the StoryBlockViewController is instantiated; StoryBlockViewController(source: .discover). By default, the feed will use the .discover content source.

Other content sources include

Channel

Displays content from the specified channel id.

Note: The user will only see videos they have not viewed before. If the user has viewed all the videos for a channel similar videos will automatically be provided.

let channelID = "<Channel ID>"
let storyBlockVC = StoryBlockViewController(source: .channel(channelID: channelID))

Channel Playlist

Displays content from the specified playlist id.

Note: Unlike the channel content source, only content in the playlist will be shown to the user.

let channelID = "<Your Channel ID>"
let playlistID = "<Playlist ID>"
let storyBlockVC = StoryBlockViewController(source: .channelPlaylist(channelID: channelID, playlistID: playlistID))

Dynamic Content

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

let channelID = "<Channel ID>"
let parameters: DynamicContentParameters = ["<cohort key>": ["<cohort value 1>", "<cohort value 2>"]]
let storyBlockVC = StoryBlockViewController(source: .dynamicContent(channelID: channelID, parameters: parameters))

Hashtag Playlist

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

let channelID = "<Channel ID>"
let singleHashtag = "dogs"
let storyBlockVC = StoryBlockViewController(source: .hashtagPlaylist(channelID: channelID, filterExpression: singleHashtag))

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

let channelID = "<Channel ID>"
let filterExpression = "(and sport (or food comedy))"
let storyBlockVC = StoryBlockViewController(source: .hashtagPlaylist(channelID: channelID, filterExpression: filterExpression))

Single Video or Live Stream

Displays a single video or live stream content.

let videoOrLiveStreamID = "<Video or LiveStream ID>"
let storyBlockVC = StoryBlockViewController(source: .singleContent(videoOrLiveStreamID: videoOrLiveStreamID))

Video Ads

Displays video ads based on vast XML.

// Specifies which channel the video ads should be created under.
let adChannelId = "<Channel ID>"
// The vast XML.
let vastXml = "<Vast XML>"
let storyBlockVC = StoryBlockViewController(source: .videoAds(adChannelId: adChannelId, vastXml: vastXml))

Story Block Configuration

StoryBlockViewController provides a StoryBlockConfiguration API to configure the UI elements of the video player. A story block's video player can be configured differently when displaying in embedded mode or when expanded to full screen. Please refer to API documentation for more details.

let storyBlockVC = StoryBlockViewController(source: .discover)
var configuration = StoryBlockConfiguration()


// Hide the share button for embedded mode
configuration.shareButton.isHidden = true
// Hide the share button for full screen mode
configuration.fullScreenPlayerView.shareButton.isHidden = true

// Configuring the sharing URL for embedded mode
configuration.shareButton.behavior.baseURL = URL(string: "your.custom.url")
// Configuring the sharing URL for full screen mode
configuration.fullScreenPlayerView.shareButton.behavior.baseURL = URL(string: "your.custom.url")

// Configuring CTA for embedded mode
configuration.ctaButton.contentConfiguration.backgroundColor = <Color>
configuration.ctaButton.contentConfiguration.textColor = <Color>
configuration.ctaButton.contentConfiguration.font = <Font>
// Configuring CTA for full screen mode
configuration.fullScreenPlayerView.ctaButton.contentConfiguration.backgroundColor = <Color>
configuration.fullScreenPlayerView.ctaButton.contentConfiguration.textColor = <Color>
configuration.fullScreenPlayerView.ctaButton.contentConfiguration.font = <Font>

// Configuring player style for embedded mode
configuration.playerStyle = .fit
// Configuring player style for full screen mode
configuration.fullScreenPlayerView.playerStyle = .fit

// Show or hide the countdown timer for embedded mode. Default is hidden
configuration.countdownTimerConfiguration.isHidden = false
// Show or hide the countdown timer for full screen mode. Default is hidden
configuration.fullScreenPlayerView.countdownTimerConfiguration.isHidden = false

// Configuring the behavior on first display
configuration.onFirstDisplay = .unmuted // Or .default

// Show playback button for embedded mode
configuration.playbackButton.isHidden = false
// Show playback button for full screen mode
configuration.fullScreenPlayerView.playbackButton.isHidden = false

// Disable autoplay
configuration.autoplay.isEnabled = false

// Disable full screen mode(full screen icon is hidden)
configuration.playerFullScreen.isEnabled = false

// Hide ad badge for embedded mode
configuration.sponsored.isHidden = true
// Hide ad badge for full screen mode
configuration.fullScreenPlayerView.sponsored.isHidden = true

// Hide player caption for embedded mode
configuration.playerCaption.isHidden = true
// Hide player caption for full screen mode
configuration.fullScreenPlayerView.playerCaption.isHidden = true

// Hide player video detail button(ellipsis button) for embedded mode
configuration.videoDetailButton.isHidden = true
// Hide player video detail button(ellipsis button) for full screen mode
configuration.fullScreenPlayerView.videoDetailButton.isHidden = true

// Set the viewConfiguration property to apply the changes
storyBlockVC.viewConfiguration = configuration

Receive story block events

  1. Set the delegate

storyBlockVC.delegate = self
  1. Conform to StoryBlockViewControllerDelegate protocol

func storyBlockDidLoadFeed(
    _ viewController: StoryBlockViewController
) {
    debugPrint("Story block loaded successfully.")
}

func storyBlock(
    _ viewController: StoryBlockViewController,
    didFailToLoadFeed error: StoryBlockError
) {
    debugPrint("Story block did fail loading.")
    if case .contentSourceError(let feedContentSourceError) = error,
       case .emptyFeed = feedContentSourceError {
        // This is a specific error.
        // SDK will trigger this error when the story block is empty.
        // For example, this error will be triggered when loading an empty playlist.
    } else {
        // Other error
    }
}

Last updated