Skip to main content
iOS Player SDK
Updated over a week ago

Prerequires

The minimum deployment version for the player is iOS SDK v.15+.

Download The Build

Note

Ask your Customer Success Manager for a link to download the SDK.

Setup

  1. Download the SDK file, which includes three xcframeworks: anyclip-sdk-ios.xcframework, ZFPlayer.xcframework, and GoogleInteractiveMediaAds.xcframework.

  2. Manually integrate these files into your project.

  3. Ensure that the 'Embed and Sign' option is set for each framework.

Usage

Importing the AnyClip player:

import AnyClipPlayer

Initializing the player:

Use the publisherId and widgetId provided to you by your AnyClip Customer Success Manager.

let playerView = AnyClipPlayer(publisherId: publisherlD, widgetID: widgetID, viewController: hostingViewController)

Embedding the ACPlayerView in a container view:

playerView.embed(in: playerContainer)

Setting the playlist ID, playlist URL or GUID:

playerView.playlistID = videoID //for playback of a single video (use the video distribution id) //or playerView.playlistID = playlistID //for playback of an entire playlist//or //or playerView.playlistURL = playlistURL //for playback of an automatically generated playlist which is based on the content of the webpage in the “playlistUrl”.

playerView.videoGUIDs = videoGUIDs // Receives array of GUID strings

Note

Only one of the above parameters (playerView.playlistID / playerView.videoGUIDs) can be supported at once.

Reusing the existing player, but loading a different configuration:

playerView.reloadConfiguration(for: publisherlD, widgetID:widgetID)

Adding play and pause functions

To add play and pause functions, use the following:

anyClipPlayer.play() anyClipPlayer.pause()

Adding Fullscreen Support

  1. Set the orientationWillChangeHandler:

    playerView.orientationWillChangeHandler = { [weak self] player, isFullScreen in if let appDelegate = UIApplication.shared.delegate as? AppDelegate { appDelegate.isFullScreen = isFullScreen } self?.setNeedsStatusBarAppearanceUpdate() }
  2. Add this behavior to your AppDelegate.

    }class AppDelegate: UIResponder, UIApplicationDelegate { var isFullScreen:Bool = false func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { if isFullScreen { return .landscape } return .portrait class AppDelegate: UIResponder, UIApplicationDelegate { var isFullScreen:Bool = false func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { if isFullScreen { return .landscape } return .portrait }
  3. Add this method to your HostingViewController:

    overridevarshouldAutorotate:Bool{playerView?.shouldAutorotate??false}overridevarprefersStatusBarHidden:Bool{playerView?.isStatusBarHidden??false}overridevarsupportedInterfaceOrientations:UIInterfaceOrientationMask{ifplayerView?.isFullScreen??false{return.landscapeLeft}return.portrait}override var shouldAutorotate: Bool { playerView?.shouldAutorotate ?? false } override var prefersStatusBarHidden: Bool { playerView?.isStatusBarHidden ?? false } override var supportedInterfaceOrientations: UIInterfaceOrientationMask { if playerView?.isFullScreen ?? false { return .landscapeLeft } return .portrait }
  4. To disable full-screen rotation if the view controller disappears, you can adapt the ViewController to life-cycle events.

    override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) playerView.hostingViewControllerDidDisappeared = false } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) playerView.hostingViewControllerDidDisappeared = true } @objc private func appDidBecomeActive() { playerView.applicationDidMoveToBackground = false } @objc private func appDidMoveToBackground() { playerView.applicationDidMoveToBackground = true

Scrollview Event

If the AnyClip player is placed in ScrollView or NestedScrollView, you'll need register it to handle scroll events.

playerView.register(scrollView:scrollView)

Error Handling

To handle player events use the errorHandler, which delegates errors to your

HostingViewController.

There are three types of errors:

public enum AnyClipPlayerError: 
Error { case network(error:URLError)
case player(error:Error)
case imaAds(error:IMAAdError) }

Event observing

For observe Player Event implement this method

anyClipPlayer.setPlayerEventObserver

For observe Social Event implement this method

anyClipPlayer.setSocialEventObserver

For observe Ad Event implement this method

anyClipPlayer.setAdEventObserver

For observe Playback Event implement this method

anyClipPlayer.setPlaybackEventObserver

Code example for collecting events:

playerView.setPlaybackEventObserver() { [weak self] playbackEvent in
// send every playback event to customer backend
CustomerEventService.sendEventToCustomerApi(event: playbackEvent)
}

playerView.setAdEventObserver { [weak self] adEvent in
// send specific event to another endpoint
if adEvent?.type == "acp" {
CustomerEventService.adCompleteWatched(adtagUID: adEvent?.tagUID)
}
}

playerView.setSocialEventObserver { [weak self] socialEvent in
// made some interaction inside the customer app if a needed event occurs
if socialEvent?.type == "clp" {
self?.showBanner()
}
}

// didn't implement 'setPlayerEventObserver' method. In that case all Player Evens will send to https://pixel.anyclip.com/vmp.gif

Customization

You can customize the AnyClip player using AnyClipPlayerAppearance by setting the following attributes.

AnyClipPlayerAppearance Attributes

Description

Default

playPauseBtnColor

Sets the play/pause button color

.white

fullscreenBtnColor

Sets the fullscreen button color

.white

muteBtnColor

Sets the mute/unmute button color

.white

ccBtnColor

Sets enable/disable subtitles button color

.white

nextBtnColor

Sets the next video button color

.white

trackTitleColor

Sets the track title text color

.white

activityColor

Sets the activity indicator color

.white

brandLeftTextAppearance

Sets the brand left text view appearance

nil

brandRightTextAppearance

Sets the brand left text view appearance

nil

topToolViewColor

Set the background color for the topToolView

nil

topToolViewImage

Sets the background image for the top ToolView

"A shadow image"

bottomToolViewColor

Sets the background color for the bottomToolView

UICol)or.black.withAlphaComponent(0.8

bottomToolViewImage

Sets the background image for the bottomToolView

nil

sliderMaximumTrackTintColor

Sets the slider color

UIColor.white.withAlphaComponent(0.8)

sliderMinimumTrackTintColor

Sets the slider progress color

.white

sliderBufferTrackTintColor

Sets the cache progress color

UIColor.white.withAlphaComponent(0.4)

sliderHeight

Sets the slider height

3

sliderTumbImage

Sets the slider thumb image

"Slider Thumb image"

sliderThumbSize

Sets the slider thumb size

CGSize(width: 120, height: 120)

bottonSliderMaximumTrackTintColor

Sets the bottom slider color

.clear

bottonSliderMinimumTrackTintColor

Sets the bottom slider progress color

.white

bottonSliderBufferTrackTintColor

Sets the bottom slider cache color

UIColor.white.withAlphaComponent(0.5)

bottonSliderHeight

Sets the bottom slider height

3

Customization usage

Apply the customization in the following way:

let appearance appearance.trackTitleColor appearance.playPauseBtnColor appearance.activityColor = AnyClipPlayerAppearance() = .red = .red = .red appearance.fullScreenBtnColor = .green appearance.brandLeftTextAttributes = [NSAttributedString.Key.foregroundColor: UlColor.red, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12, weight: .bold), NSAttributedString.Key.underlineColor: UIColor.green, NSAttributedString.Key.underlineStyle: 1] appearance.timeRangeTextColor = .blue appearance.sliderBufferTrackTintColor = .green appearance.sliderMaximumTrackTintColor = .red appearance.sliderMinimumTrackTintColor = .yellow appearance.bottonSliderBufferTrackTintColor = .green appearance.bottonSliderMaximumTrackTintColor = .red appearance.bottonSliderMinimumTrackTintColor = .yellow // set appearance playerView.appearance = appearance
Did this answer your question?