VLPlayer SDK - iOS
  • 29 Jul 2021
  • 6 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

VLPlayer SDK - iOS

  • Dark
    Light
  • PDF

Article summary

VLPlayer SDK - iOS
(version 2.4.4)

Setup

First, you’ll need to install the framework provided to you into your iOS app. Add the VLPlayer.framework to your target in the project editor by adding it as an Embedded Binary in the General section. You will also need the GoogleInteractiveMediaAds.framework and AmazonIVSPlayer.framework as an embedded binary. This SDK requires that you are using Xcode 12.5 nd Swift 5. You would need to select “Audio, AirPlay and Picture In Picture” option in Sign- ing & Capabilities under Background Modes.

Next, import the header - VLPlayer in the View-Controller you will use to load the VLPlayer iOS SDK. Developers can interact with the Player SDK by using the VLPlayer class:

Screen Shot 2020-05-15 at 1.52.39 PM

Once the header is imported in your View-Controller class, you simply need to initialize the VLPlayer iOS SDK:

Screen Shot 2020-05-15 at 1.53.58 PM

initVLPlayer() method initialises SDK object & allows your code to add configurations to player. You may use these configuration methods to manage Video Player & its layer:

List of supported Configuration Methods:

MethodParametersNotes
setIconColor()color (String) - requiredSets color to already used icons in Player - eg - Play, Pause, full screen etc. In argument you need to pass hex value.
setTextColor()color (String) - requiredSets color to already Labels in Player - eg - Video Title. In argument you need to pass hex value
setProgressBarBGColor()color (String) - requiredSets background color to video progress slider. In argument you need to pass hex value.
setProgressBarColor()color (String) - requiredSets progress color to video progress slider. In argument you need to pass hex value.
shouldAutoplay()autoplay (Bool) - requiredSets if video playback should start with launching video player without user interaction required. If true player will start playback right away.
shouldPlayMuted()isMuted (Bool) - requiredMethod to set if a video has to be played in mute state.
setVolumeLevel()volumeLevel (Int) - requiredMethod to set volume of video playback. Parameter volumeLevel is Int value which goes from 1~ 100

After configuration, you would need to set source of video to SDK player everytime a new instance of video player needs to be created. This method requires attributes to be passed, mentioned below.
Important: Please add setSource method on main thread to ensure seamless working of player & maintaining view hierarchy. Use DispatchQueue.main.async.

image.png

image.png

initVLPlayer & setSource methods needs to be used for every new instance of player.
Having separate init methods for each player makes sure we can have different configs for each player instance.

setSource method has a callback method as a parameter, which has player which you can add resize based on usage.
Initialize this method with -

  • Valid ViewLift Token

  • A ViewLift video ID

  • Video Player Tag - String val for tagging video player instance - this tag will come with every event to identify the instance of player

  • Bool value to set if video player has to be launched in fullscreen mode only

  • Custom Controls view to replace default VL player controls

  • adUrl - URLs for ads

  • playerProgressInterval - Specify interval when to get progress of player. Default value is 30 seconds and value cannot be less than 1.

  • is CustomLoaderAdded - Tell if custom loader indicator is being added. Default value is false.

  • Callback → which provides better visibility about the response of this method, including boolean value to provide info if this method worked successfully or not & a video player view instance.

Methods & Events
Below, you’ll find the list of supported methods and events for the player.

To listen for events, you need to first add the videoPlaybackDelegate to your UIViewController class. After that, you can add the following line just before you initialize the player:
Screen Shot 2020-05-15 at 2.09.26 PM

List of supported Methods:

MethodParametersNotes
play()Plays the video or advertisement from a stopped/paused state.
pause()Pauses the video or advertisement from a playing state.
destroy()(Previously was dispose(), please update to destroy()). Destroys the video player, stops any processes, and does any necessary clean up.
goFullScreen()Use this method to move video player in full screen mode.
removeFullScreen()Use this method to move video player in small screen mode - If there is no small screen player “mode”, this method will remove full screen video player from screen.
seekTo()seconds: DoubleUse this method to seek current play-ing video to a specific position.
getVideoPlayerView()This method will respond with UIView - player view, you may use it when you need to make changes to player view.
startTime()seconds: DoubleUse this method to set a start position for a video to start.
getCurrentTime()Returns current time of video being played.
getSource()Returns source of video being played. Returns dictionary - name & id.
isAutoPlay()Returns (true/ false) state of autoplay.
isMuted()Returns (true/ false) state of vol-ume(mute or not).
getVolumeLevel()Returns value of volume currently video is played (0~100).
getState()Returns state of player - Paused, Playing, Playing+Casting, Buffering, Complete, Error, Advertisement.
getPlayerVersion()Returns version of Viewlift player SDK version.
getCurrentVideoTimeLeft()Returns time left of video playback.
getCurrentVideoDuration()Returns total video duration in Double.
setNextVideo()videoId: String, adTag: StringThis method would be used to set next video id to be played within an instance of VLPlayer once currently playing video gets finished. You may add new adTag(optional) using this method.
playNextVideo()videoID: String, vlToken: String, adTag: StringThis method will replace current play-ing video with either the one set using setNextVideo method or you may add new video ID & token(optional). You may add new adTag(optional) using this method.
isPictureInPictureSelected()Returns (true/false) state of Picture In Picture selected or not.
setupPictureInPicture()This method should be used for set-ting up picture in picture if custom player UI is passed to player sdk. This method should be called after setSource() response.
pictureInPictureClicked()isPipSelected:BoolThis method will be used to start and stop picture in picture. This method is only used when we are passing cus-tom controls to player sdk and custom controls has picture in picture functionality.

List of supported Events:
List-of-supported-Eventsios.png

Video Fetch Errors

VLPlayer SDK responds with descriptive errors that may happen due to network, wrong video id/ token passed. iOS SDK offers error as an object - VLError. This comes as an attribute to videoFetchError() event.
VLError comprise of 5 variables:
isSuccess: Bool
isPlayable: Bool
errorCode: String
errorMessage: String
vl_errorCode: String

Example: (Used in sample code)
Is content playable - false (isPlayable)
Content Fetched successfully - false (isSuccess)
Error Code - Token Invalid (errorCode)
Error Message - Unauthorized (errorMessage)
Error VL Code - VL_401 (vl_errorCode)

Possible ViewLift Errors:

CodeErrorMessageDescription
VL_401Token InvalidThere was an error playing the videoAuthorization with the token did not succeed. Token can be expired or inappropriately manipulated. A new, valid token is required.
VL_400INVALID_PARAMSInvalid params were passed to the API or Video ID not providedThere was an issue with the internal SDK making an API request to the ViewLift backend. Please contact ViewLift support if this occurs.
VL_500VIDEO_NOT_EXISTSThe video does not existThe video that was requested does not exist. Please check the video ID and pass in a proper video ID associated to your account.
VL_600Fail to Start PIPLocalised description from AVPlayerThe video failed to start in picture in picture mode.
VL_601PIP_NOT_SUPPORTEDPicture in Picture not supportedPicture in Picture is not supported in platform.

New in this version :

  • Added Support for showing custom loader indicator by hiding default player loader.
  • Added Support to get player progress by adding custom interval.

For questions or issues regarding the Player SDK or integrations, contact support@viewlift.com.


Was this article helpful?