Live Playback
To play a live stream from Quickplay Platform, follow the steps described in Secure Playback, and update the platform asset to indicate you are trying to play a Live stream.
A PlatformAsset
for playing a Live Stream could be constructed with APIs from ContentAuthorizer by providing the following:
- Content Id: Unique identifier of the content
- Media Format: HLS | DASH | SmoothStream
- DRM: Fairplay | Widevine
- Content Type: Live
- Catalog Type: channel | event | sportsliveevent
- Playback Mode: Live | Restart | Catchup
- Start Time: Start time of the Live Program
- Required for playback modes
restart
andcatchup
, optional otherwise
- Required for playback modes
- End Time: End time of the Live Program
- Required for playback mode
catchup
, optional otherwise
- Required for playback mode
// create live streaming asset
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId,
contentType: .live,
catalogType: "channel",
mediaFormat: .hls,
drm: .fairplay,
playbackMode: .live)
Seeking in live streams
When playing a Live stream, the player always starts playing from the Live Edge. To seek anywhere within the live window, you can use the standard seek
APIs, refer to Basic Playback. The seek position is always relative to the start of the live window. The player will try to maintain the same live offset after a seek.
To force the player to play from Live Edge of the current Live Window, use the seekToLiveEdge
API. The currentOffsetFromLiveEdge
API can be used to determine if the player is currently playing at or beginning the Live Edge.
Player APIs for live playback positions:
Property Name | Type | Description |
---|---|---|
currentEpochTime | TimeInterval | Current time expressed in epoch. |
currentOffsetFromLiveEdge | TimeInterval | The time difference between current playback position and live edge position, in seconds. |
currentTime | TimeInterval | The current playback position (in seconds) expressed within the limits of the seekable range. |
seekableRange | Range<TimeInterval> | Live window range (lowerbound - window start in seconds, upperbound - window end in seconds) |
Listening to live program end
When playing a live program or event, Quickplay platform authorizes the playback for the current action program/event. program/event should be re-authorized again.
When the current live program (restart
, live
modes) ends, player notify delegate the streamtimelineevent
with eventName as StreamTimelineEvent.LIVE_PROGRAM_END
.
func didReceive(event: StreamTimelineEvent, suggestedAction: Action, metadata: StreamTimelineMetadata?) {
switch event {
case .liveProgramEnd:
// handle program end
}
}
Playback Modes
Restart
If you are looking to offer Restart or Play from Beginning feature for your users, setup the asset as shown below. The startTime and endTime of the program must be provided in ISO8601 format.
// create live streaming asset
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId,
contentType: .live,
catalogType: "channel",
mediaFormat: .hls,
drm: .fairplay,
playbackMode: .restart,
startTime: programStartTime,
endTime: programEndTime)
Set the intial playback time preference as zero
to ensure the live stream plays from beginning of Live Window instead of the Live Edge.
if let contentURL = URL(string: playbackAsset.contentUrl) {
let avURLAsset = AVURLAsset(url: contentURL)
let player = FLPlayer.player(asset: avURLAsset)
// add player's playback view to your controller
// player.playbackView
player.set(preferences: [.initialPlaybackTime(time: 0.0)])
player.play()
}
Setting any other positive value would be construed as seconds from start of the stream. For instance, setting 300.0 would start the stream 5 minutes from the beginning of live window.
// Start stream 5 minutes from beginning of stream
player.set(preferences: [.initialPlaybackTime(time: 300.0)])
Catchup
If you are looking to offer Catchup on an already ended Live program for your users, setup the asset as shown below. The startTime
and endTime
indicate the program start time and end time respectively and these are mandatory when trying to play in catchup
mode. The startTime and endTime must be provided in ISO8601 format.
// create live streaming asset
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId,
contentType: .live,
catalogType: "channel",
mediaFormat: .hls,
drm: .fairplay,
playbackMode: .catchup,
startTime: programStartTime,
endTime: programEndTime)
seekToLiveEdge
API would be a no-op while playing catchup stream. If you are looking to jump to current live edge of a Catchup
playback, you must re-authorize the playback in live
playbackMode and setup a new player instance.