Amp Downloader
The AmpDownloader plugin allows you to download VOD content to watch later on without any network access.
You can check out our basic implementation, please refer to our application samples:
Installation
To install the AmpDownloader just manually add the framework or add it through CocoaPods with the same pod name AmpDownloader
. The steps are the same as with the installation of our documentation.
Implementation
You need a working implementation of the AmpPlayer before using this plugin. If you need the implementation guide for AmpPlayer please refer to our documentation.
Adding a new Download
After importing the libraries to the file, you can download a new file with the startNewDownload
method.
let download = AmpDownloadManager.startNewDownload(title: VIDEO_TITLE, url: url)
List the download
To check the list of downloads the user has started, you can check the file AmpDownloads.plist
in the document directory and decode the file using the AmpDownload
class.
let path:String = {
let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
return documentDirectory.appending("/AmpDownloads.plist")
}()
func getDownloads() -> [AmpDownload] {
var array:[AmpDownload] = []
if let data = FileManager.default.contents(atPath: path),
let decodedArray = try? PropertyListDecoder().decode(Array<AmpDownload>.self, from: data) {
array = decodedArray
}
return array
}
Other functionalities
There are also other methods for managing your downloads:
AmpDownloadManager.pauseDownload
: Pauses a download
AmpDownloadManager.resumeDownload
: Resumes a download
AmpDownloadManager.cancelDownload
: Cancels an on going download
AmpDownloadManager.deleteDownload
: Deletes a downloaded asset
Recover old downloads
To continue downloading content after reopening the app you must call this method on the launch of it.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
AmpDownloadManager.restoreDownloads()
return true
}
Additional Information
This guide was written on 7/26/2024 and it’s last revision was made on 7/26/2024. If you need any additional support please contact us through our offical support email.