HTTP Live Streaming (HLS) download manager to offline playback.
- iOS 10.0+
- Xcode 8.0+
- Swift 3.0+
Add below to your Cartfile
.
github "r-plus/HLSion" "master"
Thus build framework.
carthage update HLSion
import HLSion
let url = URL(string: "https://...m3u8")!
let hlsion = HLSion(url: url, name: "identifier").download { (progressPercentage) in
// call while each file downloaded.
}.finish { (relativePath) in
// call when complete or cancel download task finish.
}.onError { (error) in
// call when error finish.
}
// cancelable.
hlsion.cancelDownload()
// delete downloaded asset.
hlsion.deleteAsset()
Play after download.
guard let localUrl = hlsion.localUrl else {
// This instance not yet downloaded.
return
}
let localAsset = AVURLAsset(url: localUrl)
let playerItem = AVPlayerItem(asset: localAsset)
let player = AVPlayer(playerItem: playerItem)
player.play()