- 29 Jul 2021
- 6 Minutes to read
- Contributors
- Print
- DarkLight
- PDF
VLPlayer SDK - iOS
- Updated on 29 Jul 2021
- 6 Minutes to read
- Contributors
- Print
- DarkLight
- PDF
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:
Once the header is imported in your View-Controller class, you simply need to initialize the VLPlayer iOS SDK:
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:
Method | Parameters | Notes |
---|---|---|
setIconColor() | color (String) - required | Sets color to already used icons in Player - eg - Play, Pause, full screen etc. In argument you need to pass hex value. |
setTextColor() | color (String) - required | Sets color to already Labels in Player - eg - Video Title. In argument you need to pass hex value |
setProgressBarBGColor() | color (String) - required | Sets background color to video progress slider. In argument you need to pass hex value. |
setProgressBarColor() | color (String) - required | Sets progress color to video progress slider. In argument you need to pass hex value. |
shouldAutoplay() | autoplay (Bool) - required | Sets if video playback should start with launching video player without user interaction required. If true player will start playback right away. |
shouldPlayMuted() | isMuted (Bool) - required | Method to set if a video has to be played in mute state. |
setVolumeLevel() | volumeLevel (Int) - required | Method 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.
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:
List of supported Methods:
Method | Parameters | Notes |
---|---|---|
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: Double | Use 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: Double | Use 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: String | This 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: String | This 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:Bool | This 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:
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:
Code | Error | Message | Description |
---|---|---|---|
VL_401 | Token Invalid | There was an error playing the video | Authorization with the token did not succeed. Token can be expired or inappropriately manipulated. A new, valid token is required. |
VL_400 | INVALID_PARAMS | Invalid params were passed to the API or Video ID not provided | There was an issue with the internal SDK making an API request to the ViewLift backend. Please contact ViewLift support if this occurs. |
VL_500 | VIDEO_NOT_EXISTS | The video does not exist | The video that was requested does not exist. Please check the video ID and pass in a proper video ID associated to your account. |
VL_600 | Fail to Start PIP | Localised description from AVPlayer | The video failed to start in picture in picture mode. |
VL_601 | PIP_NOT_SUPPORTED | Picture in Picture not supported | Picture 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.