Skip to content

castlabs/drmtoday-avplayer-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HLS Catalog with FPS and DRMtoday: Using AVFoundation to play and persist HTTP Live Streams with FairPlay Streaming Content Protection

This sample demonstrates how to use the AVFoundation framework to play HTTP Live Streams hosted on remote servers as well as how to persist the HLS streams on disk for offline playback.

Sample is prepared by Apple and extended to make it compatible with DRMtoday.

To learn more about FairPlay Streaming, see the FairPlay Streaming Programming Guide which is part of the "FPS Server SDK" package. The latest version of this package can be found at https://developer.apple.com/streaming/fps.

Using the Sample

Build and run the sample on an actual device running iOS 11.0 or later using Xcode. The APIs demonstrated in this sample do not work on the iOS Simulator.

This sample provides a list of HLS Streams that you can playback by tapping on the UITableViewCell corresponding to the stream. If you wish to manage the download of an HLS stream such as initiating an AVAggregateAssetDownloadTask, canceling an already running AVAggregateAssetDownloadTask or deleteting an already downloaded HLS stream from disk, you can accomplish this by tapping on the accessory button on the UITableViewCell corresponding to the stream you wish to manage.

When the sample creates and initializes an AVAggregateAssetDownloadTask for the download of an HLS stream, only the default selections for each of the media selection groups will be used (these are indicated in the HLS playlist EXT-X-MEDIA tags by a DEFAULT attribute of YES).

Adding Streams to the Sample

If you wish to add your own HLS streams to test with using this sample, you can do this by adding an entry into the Streams.plist that is part of the Xcode Project. There is five important keys you need to provide values for:

name: What the display name of the HLS stream should be in the sample.

playlist_url: The URL of the HLS stream's master playlist.

is_protected: Whether or not the stream is protected using FPS.

minimum_download_bitrate: Minimal bitrate of the quality that will be downloaded

content_key_id_list: An array of content key identifiers to use for loading content keys for content using FPS. The values are strings in the form of the URIs used in the X-EXT-KEY tag for loading content keys. The exact format is described in DRMtoday documentation. For example: "skd://drmtoday?keyId=6fbf6d37cf3840c09c99ad8da1dff10b"

Additional DRMtoday specific values:

environment: DRMtoday environment (test, staging or production).

merchant: DRMtoday merchant name (for building Merchant Metadata object as defined in DRMtoday documentation)

_user_id: DRMtoday userId (for building Merchant Metadata object as defined in DRMtoday documentation)

session_id: DRMtoday sessionId (for building Merchant Metadata object as defined in DRMtoday documentation)

asset_id: DRMtoday assetId

variant_id: DRMtoday variantId of the asset

Please note that providing assetId and variantId will result in overridding content key idenfifiers from SKD URI. Additionally, requesting DRM license by assetId will work only for single key content but fail for multi-key content. To use these properties, lines 126-127 of DRMtoday.swift need to be uncommented. Please use those two properties with caution and for debugging purposes only.

Application Transport Security

If any of the streams you add are not hosted securely, you will need to add an Application Transport Security (ATS) exception in the Info.plist. More information on ATS and the relevant plist keys can be found in the following article:

Information Property List Key Reference - NSAppTransportSecurity: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33

Important Notes

Saving HLS streams for offline playback is only supported for VOD streams. If you try to save a live HLS stream, the system will throw an exception.

Main Files

AssetPersistenceManager.swift:

  • AssetPersistenceManager is the main class in this sample that demonstrates how to manage downloading HLS streams. It includes APIs for starting and canceling downloads, deleting existing assets off the users device, and monitoring the download progress.

AssetPlaybackManager.swift:

  • AssetPlaybackManager is the class that manages the playback of Assets in this sample using Key-value observing on various AVFoundation classes.

AssetListManager.swift:

  • The AssetListManager class is responsible for providing a list of assets to present in the AssetListTableViewController.

StreamListManager.swift:

  • The StreamListManager class manages loading reading the contents of the Streams.plist file in the application bundle.

ContentKeyManager.swift:

  • The ContentKeyManager class configures the instance of AVContentKeySession to use for requesting content keys securely for playback or offline use.

ContentKeyLoader.swfit:

  • ContentKeyDelegate is a class that implements the AVContentKeySessionDelegate protocol to respond to content key requests using FairPlay Streaming.

ContentKeyDelegate+Persistable.swift:

  • This extension on ContentKeyDelegate implements the AVContentKeySessionDelegate protocol methods related to persistable content keys.

Helpful Resources

The following resources available on the Apple Developer website contain helpful information that you may find useful

Requirements

Build

Xcode 9.0 or later; iOS 11.0 SDK or later

Runtime

iOS 11.0 or later.

Copyright (C) 2017-2018 Apple Inc. All rights reserved.

About

Example of AVplayer integration with DRMtoday

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages