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 MMVideoView
is being initialized with the following properties:
playerId
- The Player ID.contentId
- The Content ID of the Player.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
- Hold an outlet to your container view height.
- Implement
mmVideoViewHeight(_ height: CGFloat)
method ofMMVideoViewDelegate
- update the container view height using the outlet. - If your app supports orientation changes - in
viewWillTransition
method, call tommVideoView.viewWillTransition(coordinator)
UICollectionView item
- Hold a variable for the
MMVideoView
view height and initialize it to 0.
var mmVideoViewCellHeight: CGFloat = 0
- Implement
mmVideoViewHeight(_ height: CGFloat)
method ofMMVideoViewDelegate
as follows:
func mmVideoViewHeight(_ height: CGFloat) {
self.mmVideoViewCellHeight = height
self.collectionView.performBatchUpdates(nil, completion: nil)
}
- In
sizeForItemAt
method of UICollectionViewDelegateFlowLayout, set player item height to:
CGSize(width: width, height: mmVideoViewCellHeight)
- In
willDisplay cell
method, call toself.mmVideoView.willDisplay()
for theMMVideoView
itemindexPath
. - If your app supports orientation changes - in
viewWillTransition
method, call tommVideoView.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
- Hold a variable for the
MMVideoView
view height and initialize it to 0.
var mmVideoViewCellHeight: CGFloat = 0
- Implement
mmVideoViewHeight(_ height: CGFloat)
method ofMMVideoViewDelegate
as follows:
func mmVideoViewHeight(_ height: CGFloat) {
self.mmVideoViewCellHeight = height
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
- In
heightForRowAt
method ofUITableViewDelegate
, set player item height toself.mmVideoViewCellHeight
. - In
willDisplay cell
method, call toself.mmVideoView.willDisplay()
for theMMVideoView
itemindexPath
. - If your app supports orientation changes - in
viewWillTransition
method, call tommVideoView.viewWillTransition(coordinator)
:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
mmVideoView.viewWillTransition(coordinator)
}