Skip to content

glaphi/HTTPLiveStreaming

Repository files navigation

HLS Catalog with FPS: 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.

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.2 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 AVAssetDownloadTask, canceling an already running AVAssetDownloadTask 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 AVAssetDownloadTask 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 are two 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.

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. For example: "skd://twelve"

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

AssetPersistenveManager.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 AssetResourceLoaderDelegate to use for requesting content keys securely for playback or offline use.

AssetResourceLoaderDelegate.swfit:

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

AssetResourceLoaderDelegate+Persistable.swift:

  • This extension on AssetResourceLoaderDelegate implements the 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.2 SDK or later

Runtime

iOS 11.2 or later.

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages