VoltaxSDK 1.3.0

VoltaxSDK 1.3.0

Maintained by Alon Shprung, Oded Regev.



VoltaxSDK 1.3.0

  • By
  • Boris Kalim

Voltax SDK for iOS

This library provides an easy integration with Voltax player into a native iOS app.

Implementation

Add the SDK to your project

CocoaPods

  • Set dependency as follows: pod 'VoltaxSDK'
  • Execute pod install in Terminal.
  • Open workspace file and run.

The MMVideoView Class

MMVideoView is the main class of the Voltax SDK.

Create a container view to hold the MMVideoView

The MMVideoView should be loaded into a container view (UIView). This container view can be the contentView of a UICollectionView or UITableView cell.

Initialize a MMVideoView instance

The MMVideoViewis being initialized with the following properties:

  1. playerId - The Player ID.
  2. contentId - The Content ID of the Player.
  3. articleUrl (optional) - The URL of the article page.

Initialize a new instance of MMVideoView using one of the following constructors:

let mmVideoView = MMVideoView(playerId: PLAYER_ID, contentId: CONTENT_ID)
let mmVideoView = MMVideoView(playerId: PLAYER_ID, contentId: CONTENT_ID, articleUrl: ARTICLE_URL)

MMVideoViewDelegate

You have to impelement MMVideoViewDelegate and set it to the instance of the MMVideoView. The MMVideoViewDelegate has one methods:

mmVideoViewHeight(_ height: CGFloat) - See "MMVideoView Height Changes" section below.

Set the delegate to MMVideoView instance:

mmVideoView.delegate = self

Load the Voltax player to the MMVideoView

In order to load the player to your MMVideoView instance, use the load() method.

@IBOutlet weak var mmVideoViewContainer: UIView!

mmVideoView.load(mmVideoViewContainer)

Or for UICollectionView or UITableView, in willDisplay cell method:

mmVideoView.load(cell.contentView)

MMVideoView Height Changes

Custom View

  1. Hold an outlet to your container view height.
  2. Implement mmVideoViewHeight(_ height: CGFloat) method of MMVideoViewDelegate - update the container view height using the outlet.
  3. If your app supports orientation changes - in viewWillTransition method, call to mmVideoView.viewWillTransition(coordinator)

UICollectionView item

  1. Hold a variable for the MMVideoView view height and initialize it to 0.
var mmVideoViewCellHeight: CGFloat = 0
  1. Implement mmVideoViewHeight(_ height: CGFloat) method of MMVideoViewDelegate as follows:
func mmVideoViewHeight(_ height: CGFloat) {
    self.mmVideoViewCellHeight = height
    self.collectionView.performBatchUpdates(nil, completion: nil)
}
  1. In sizeForItemAt method of UICollectionViewDelegateFlowLayout, set player item height to:
CGSize(width: width, height: mmVideoViewCellHeight)
  1. In willDisplay cell method, call to self.mmVideoView.willDisplay() for the MMVideoView item indexPath.
  2. If your app supports orientation changes - in viewWillTransition method, call to mmVideoView.viewWillTransition(coordinator) and invalidate the collectionView layout. For example:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    collectionView.collectionViewLayout.invalidateLayout()
    mmVideoView.viewWillTransition(coordinator)
}

UITableView item

  1. Hold a variable for the MMVideoView view height and initialize it to 0.
var mmVideoViewCellHeight: CGFloat = 0
  1. Implement mmVideoViewHeight(_ height: CGFloat) method of MMVideoViewDelegate as follows:
func mmVideoViewHeight(_ height: CGFloat) {
    self.mmVideoViewCellHeight = height
    self.tableView.beginUpdates()
    self.tableView.endUpdates()
}
  1. In heightForRowAt method of UITableViewDelegate, set player item height to self.mmVideoViewCellHeight.
  2. In willDisplay cell method, call to self.mmVideoView.willDisplay() for the MMVideoView item indexPath.
  3. If your app supports orientation changes - in viewWillTransition method, call to mmVideoView.viewWillTransition(coordinator):
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    mmVideoView.viewWillTransition(coordinator)
}