Player Configuration
Setting Peak Bitrate
Configures the Player's variant adaptation logic with the passed maximum bitrate constraint.
player.set(preferences: [.preferredPeakBitRate(bitrate: 842_742)])
If the preferences are set prior to player entering loaded state, these preferences would be considered as on load preferences and this would override any preference if any set via load(with preferences: Preference...)
method.
If Preferences are set during playback, they would be applied to the player immediately.
Setting Initial Forward Buffer Duration
Setting this preferredInitialForwardBufferDuration to optimise the playback start up time. This will be applied only before the playback start.
To reset set the value to 0.0. it will use the system prefered buffer. Setting this preference before calling play()
or load()
API will be effective.
player.set(preferences: [.preferredInitialForwardBufferDuration(duration: 1.0)])
Setting Forward Buffer Duration After Rebuffer
To change the playback preference, either reset it to the default value by setting the value to 0.0 or we can set the new value to be used after playback starts. New value will be set only after the video has started playing. Setting this to 0.0, will use the system buffer duration which is based on different factors. To reset, set the value to 0.0. it will use the system prefered buffer.
player.set(preferences: [.preferredForwardBufferDurationAfterRebuffer(duration: 8.0)])
Setting Initial Playback Time
The initial time from which player should start playback.
player.set(preferences: [.initialPlaybackTime(time: 10.0)])
Setting Maximum Resolution
Preferred Max limit on the resolution of the video to be rendered by the player.
Setting the preferred maximum resolution for playback video using preferredMaximumResolution by passing the size (height and width).
player.set(preferences: [.preferredMaximumResolution(size: CGSize(width: 1080, height: 720))])
Setting Network Resources For Live Streaming
canUseNetworkResourcesForLiveStreamingWhilePaused is a boolean value that indicates whether the player item can use network resources to keep the playback state up to date, while being paused. When this property is set to true, the seekableTimeRanges property will be periodically updated to reflect the current state of the live stream.
player.set(preferences: [.canUseNetworkResourcesForLiveStreamingWhilePaused(paused: true)])
Setting MaximumResolution For Expensive Networks
By setting this preference, player may adjust the video resolution based on network condition to improve the user’s experience.
player.set(preferences: [.preferredMaximumResolutionForExpensiveNetworks(size: CGSize(width: 1080, height: 720))])
Available from, iOS 15.0+, tvOS 15.0+
Setting starts On First Eligible Variant
Setting startsOnFirstEligibleVariant indicates whether playback starts with the first eligible variant that appears in the stream’s main playlist. The default value of this property is false.
player.set(preferences: [.startsOnFirstEligibleVariant(eligibleVariant: true)])
Available from, iOS 14.0+, tvOS 14.0+
Setting Peak Bit Rate For Expensive Networks
Setting preferredPeakBitRateForExpensiveNetworks, sets the maximum bit rate for streaming content when the player is connected to expensive network.
player.set(preferences: [.preferredPeakBitRateForExpensiveNetworks(preferredPeakBitRate: 5397000.0)])
The value of the preferredPeakBitRate property applies unconditionally. This property value has no effect if this property value is less restrictive than the preferredPeakBitRate value. Available from, iOS 15.0+, tvOS 15.0+
Protect playback from Insecure devices
Allow or disallow playback on insecure devices i.e jailbroken device. By default FLPlayer allows playback on insecure devices.
player.set(preferences: [.allowPlaybackOnInsecureDevice(allow: false)])
Enable additional security checks on top of detecting jailbreak.
// opt-in to additional checks
let additionalChecks = [.emulatorCheck, .debuggerCheck, .proxyCheck, .integrityCheck(bundleID: "com.organisation.appname")]
player.set(preferences: [.enableSecurityChecks(additionalChecks: additionalChecks)])
The following is the list of opt-in checks that can be additionally enabled:
Name | Description |
---|---|
Debugger Detection | This is used to determine if application is being debugged |
Emulator Detection | This is used to determine if application is run in emulator |
Proxy Detection | This is used to determine if HTTP proxy was set in the iOS Settings |
Device tampering Detection | This is used to determine if application has been tampered |
We recommend to integrate this checks with remotely configurable to enable/disable the each detections and pick the level of security based on the requirement via remote config.
Detemine device security status
We also publish device security status via PlatformClient
.
let device = FLPlatformCoreFactory.createDevice()
let result = device.securityStatus(bundleID: "com.org.app")
if !result.status {
// print(result.failureReason)
}
Trick Play
The factor by which playback should be sped up.
// Standard playback rate is 1 and paused is 0.
// Rates other than 0.0 and 1.0 can be used,
// if the streams supports trickplay.
player.rate = 1.25;
Picture In Picture
FLPlayer library supports PiP. The application must include Audio, Airplay & Picture in Picture
capability. Picture in picture is possible only on iPad and on selected models. This is a Platform limitation.
Airplay
Airplay 2 is supported by FLPlayer library. The application must include Audio, Airplay & Picture in Picture
capability. Please note airplaying a fairplay protected content would require a on-demand license key, so you cannot airplay a offline content.
Now Playing Info
iOS displays now-playing information on the device lock screen and in the multimedia controls in the multitasking UI. If the user directs playback of your media to Apple TV via AirPlay, the now-playing information appears on the television screen.
If the user connects a device to an iPod accessory, such as in a car, the accessory may display now-playing information. Pass in nil
to clear the existing now playing info.
// Setting NowPlayingInfo
var nowPlayingInfo = [String: Any]()
if #available(iOS 10.3, *) {
nowPlayingInfo[MPNowPlayingInfoPropertyAssetURL] = <url>
} else {
// Fallback on earlier versions
}
// Sample inputs
nowPlayingInfo[MPMediaItemPropertyTitle] = "Content Title"
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = player.duration
nowPlayingInfo[MPMediaItemPropertyMediaType] = MPMediaType.anyVideo.rawValue
nowPlayingInfo[MPNowPlayingInfoPropertyDefaultPlaybackRate] = 1.0
nowPlayingInfo[MPMediaItemPropertyArtist] = "Artist"
nowPlayingInfo[MPMediaItemPropertyAlbumArtist] = "Album Artist"
nowPlayingInfo[MPMediaItemPropertyAlbumTitle] = "Album Title"
#if os(iOS)
player.nowPlayingInfo = nowPlayingInfo
#endif
Thumbnail Preview
Thumbnail Preview is a functionality that allows users to see a preview image of the video while seeking.
The Player
uses a series of images woven into a sprite from a given URL which is used to retrieve the corresponding image for a given playhead position.
Setup Thumbnail Preview
Create ThumbnailConfiguration
ContentThumbnailPreviewConfiguration
describes the URL, dimensions and duration of each image of each sprite.
Name | Type | Description |
---|---|---|
endPoint | String | The fully formed sprite image URL that combines the endpoint URL and generic URL suffix, which includes the flag ~index~ . Player calculates the sprite index based on given position and replaces ~index~ with the required index to construct the sprite URL. |
noOfcolumns | Int | The number of columns in each sprite image. |
noOfRows | Int | The number of rows in each sprite image. |
keyFrameDuration | Int | The time (in seconds) that each thumbnail in each sprite image corresponds to. |
thumbnailWidth | Int | The width (in pixels) of each thumbnail in each sprite image. |
thumbnailHeight | Int | The height (in pixels) of each thumbnail in each sprite image. |
let thumbnailConfiguration: ContentThumbnailPreviewConfiguration = FLPlayerFactory.thumbnailConfiguration(
endPoint: spriteURL,
noOfColumns: columns,
noOfRows: rows,
keyFrameDuration: frequency,
thumbnailHeight: height,
thumbnailWidth: width
)
Pass information to Player
Thumbnail Preview is an optional feature that can be opted into by passing ContentThumbnailPreviewConfiguration
object to the corresponding Player
(See Player creation) instance.
//If using AVURLAsset to create Player
let player = FLPlayer.player(
asset: avURLAsset,
thumbnailConfiguration: thumbnailConfiguration
)
//If using Content URL to create Player
let player = FLPlayer.player(
contentURL: contentURL,
thumbnailConfiguration: thumbnailConfiguration
)
Implement Thumbnail Preview
Calling getThumbnail API
The preview image for a particular position can be obtained by calling the getThumbnail
extension API on the Player
instance. The API returns the preview image for the given position in the form of a UIImage
.
Parameter | Type | Description |
---|---|---|
progress | TimeInterval | The position of the playhead for which the thumbnail is to be retrieved, in seconds. |
completionHandler | @escaping (UIImage) -> Void | The callback function that returns a UIImage of the thumbnail. |
player.getThumbnail(for: progress, completionHandler: { [weak self] thumbnail in
//Display preview image as required
})
This function is typically called in tandem with a scrub bar listener attached to the Player
which listens to all the seeking activity from the user.