Circle Story (iOS)

Use CircleStoryView

import UIKit
import FireworkVideo

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

    func addVideoFeedView() {
        let channelID = "<Encoded Channel ID>"
        let playlistID = "<Encoded Playlist ID>"
        let source = VideoFeedContentSource.channelPlaylist(
            channelID: channelID,
            playlistID: playlistID
        )
        let circleStoryView = CircleStoryView(source: source)
        circleStoryView.isPictureInPictureEnabled = true

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

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

Use CircleStorySwiftUIView

Content Source

Please refer to Video Feed Content Source (iOS).

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. We recommend leveraging CircleStoryView and CircleStorySwiftUIView for this purpose.

Code snippets for CircleStoryView

Code snippets for CircleStorySwiftUIView

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.

Last updated

Was this helpful?