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

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

Play and pause StoryBlock programmatically

Use StoryBlockViewController

let storyBlockVC = StoryBlockViewController(source: .discover)

// Play StoryBlock Programmatically
storyBlockVC.play()

// Pause StoryBlock Programmatically
storyBlockVC.pause()

Use StoryBlockView

let storyBlockView = StoryBlockView(source: .discover)

// Play StoryBlock Programmatically
storyBlockView.play()

// Pause StoryBlock Programmatically
storyBlockView.pause()

Last updated

Was this helpful?