GithubHelp home page GithubHelp logo

fairplay's Introduction

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.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 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 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.