t-osawa-009 / AssetDownloadWrapper

iOS AVAssetDownloadURLSession Wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AssetDownloadWrapper

A wrapper to download videos using AVAssetDownloadURLSession.

About

This is the library that wraps the function of AVAssetDownloadURLSession. Download the video and cache it to local storage.

How to implement

  • Download the video
    let url = URL(string: "https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8")!
    let urlAsset = AVURLAsset(url: url)
    let asset = AssetWrapper(urlAsset: urlAsset, assetTitle: "hoge")
    AssetDownloadManager.shared.downloadStream(for: asset) { (result) in
      switch result {
        case .success(let response):
        print(response)
        case .failure(let error):
        print(error)
      }
    }
  • Load local cache
    guard let arg = AssetDownloadManager.shared.retrieveLocalAsset(with: "hoge") else {
         return
     }
     let vc = AVPlayerViewController()
     let item = AVPlayerItem(asset: arg.0.urlAsset)
     player.replaceCurrentItem(with: item)
     vc.player = player
     present(vc, animated: true, completion: nil)

Requirements

  • Xcode 11.4
  • Swift 5.1

Installation

Add the pod AssetDownloadWrapper

# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
    pod 'AssetDownloadWrapper'
end
$ pod install

Add this to Cartfile

git "git@github.com:t-osawa-009/AssetDownloadWrapper.git"
$ carthage update

Reference Resources

CONTRIBUTING

There's still a lot of work to do here. We would love to see you involved. You can find all the details on how to get started in the Contributing Guide.

License

AssetDownloadWrapper is released under the MIT license. See LICENSE for details.

About

iOS AVAssetDownloadURLSession Wrapper

License:MIT License


Languages

Language:Swift 97.1%Language:Ruby 1.4%Language:Objective-C 1.3%Language:Makefile 0.2%