Adaptive Media Player

AmpDownloader Docs

AmpDownloader

Home / AmpDownloader


The AmpDownloader plugin, handle the downloand and offline playback using AmpPlayer for iOS. This downloader supports HLS only.

Installation

Just import the AmpDownloader.framework in your project. For more information check out the AmpCore’s documentation.

Note: Make sure to add the frameworks as Embedded Binaries or you’ll get an error about a missing image.

How to Use

Let’s first import the required frameworks:

import AmpCore
import AmpDownloader

Start a download using the function startNewDownload. This functions is available on **AmpDownloadManager* class.

let download = AmpDownloadManager.startNewDownload(title: "YOUR_TITLE", url: "YOUR_STRING_URL")

startNewDownload function return an AmpDownload class. This class has a bunch of properties to handle the stream download like id, title, if the download is completed or not, the asset to use it on AmpPlayer and the current download progress.

Warning: the title param must be a unique string.

AmpDownloaderDelegate

AmpDownloader provides a delegate to control all the events that happen while an asset is downloading. To register a object to this delegate you should use the function:

AmpDownloadManager.registerDelegate(delegate: YOUR_OBJECT)

The callback functions available are:

public func downloadStarted(asset: AmpDownloader.AmpDownload)

public func downloadPaused(asset: AmpDownloader.AmpDownload)

public func downloadResumed(asset: AmpDownloader.AmpDownload)

public func downloadCompleted(asset: AmpDownloader.AmpDownload)

public func downloadCancelled(asset: AmpDownloader.AmpDownload)

public func downloadDeleted(asset: AmpDownloader.AmpDownload)

public func downloadProgressChanged(asset: AmpDownloader.AmpDownload, progress: Float)

public func downloadStateChanged(asset: AmpDownloader.AmpDownload, mediaOption: String)

public func downloadFailed(asset: AmpDownloader.AmpDownload, error: NSError, message: String)

Download List

If you need to get the list of all the assets downloaded, you should use the funcion getDownloadList. This function return an AmpDownload’s array. But first you make sure to call **restoreDownloads* on your app delegate to get the downloaded assets. Example:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        AmpDownloadManager.restoreDownloads()
        return true
    }

Then on your ViewController:

let list = AmpDownloadManager.getDownloadList()
let firstDownload = list.first()

How to play offline Assets?

Once your asset is completed downloaded, you can pass it to AmpPlayer and the local playback will start without any problem. To do this, you just need to pass the Asset property to AmpPlayer using the play function:

override func viewDidLoad() {
    super.viewDidLoad()
    player = AmpPlayer(parentView: self.view)
    if let asset = download?.asset  {
        player.play(asset: asset)
    }

}