Video Feed

Displaying the Video Feed

Displaying a video feed can be done by using a VideoFeedViewController either programmatically or in a storyboard.

Programmatic

  1. Import FireworkVideo

  2. Create a new VideoFeedViewController

  3. Present, show or embed the instantiated VideoFeedViewController

import FireworkVideo

class ViewController: UIViewController {

    func addFeedToTabBarController() {
        let feedVC = VideoFeedViewController()
        feedVC.tabBarItem = UITabBarItem(title: "Videos", image: nil, selectedImage: nil)
        self.tabBarController?.viewControllers?.append(feedVC)
    }

    func pushFeedOnNavigationController() {
        let feedVC = VideoFeedViewController()
        self.navigationController?.pushViewController(feedVC, animated: true)
    }

    func embedFeedInViewController() {
        let feedVC = VideoFeedViewController()
        self.addChild(feedVC)
        self.view.addSubview(feedVC.view)
        feedVC.view.frame = self.view.bounds
        feedVC.willMove(toParent: self)
    }
    
}

Storyboard

Adding a VideoFeedViewController to a storyboard is easy but has limited support. Therefore, layout and customizations can only be made progrgammatically. Both layout and customizations changes can be made at anytime. This allows you to add a VideoFeedViewController via storyboard then make adjustments programmatically.

  1. Open storyboard

  2. Add and select a UIViewController

  3. In the Inspector pane, select the Identity inspector

  4. Add VideoFeedViewController as the Custom Class

  5. Make sure the Module is set to FireworkVideo

Custom Call-To-Action Button Handling

Custom Call-To-Action button handling is done via the FireworkVideoCTADelegate protocol. This provides control over what occurs when a call-to-action button is tapped.

  1. Set the delegate:

FireworkVideoSDK.ctaDelegate = self

2. Confirm to protocol:

func handleCustomCTAClick(_ viewController: PlayerViewController, url: URL) -> Bool {
    // Your custom action code here...
    return true
}

Force Refresh

A VideoFeedViewController can be hard refreshed by calling the refresh() method on the instance that should be refreshed. This functionality is useful if your feed is embedded along with other components that are also updated and you support features like pull to refresh.

Picture in Picture (PiP)

This feature allows the user to watch media while the application is in a backgrounded state. While in background mode a video will display in a floating, resizable window.

To enable PiP functionality, you’ll need to add Background Modes capability via Signing & Capabilities in your project settings. More information about this can be found here: Apple Documentation

Once the background mode is enabled, moving from an active state to a background state will immediately trigger the Picture In Picture functionality. PictureInPictureController is responsible for handling all of this functionality. PictureInPictureController retains a strong reference of AVPictureInPictureController. AVPictureInPictureController is a controller that responds to user-initiated Picture in Picture playback of video in a floating, resizable window.

let feedVC = VideoFeedViewController(
     layout: VideoFeedHorizontalLayout(),
     source: source,
     adConfiguration: adConfiguration)
     pipViewControlelr = PictureInPictureController(videoFeed: feedVC)swi

Last updated