Skip to content

FactorialComplexity/FYCachedURLAsset

Repository files navigation

FYCachedURLAsset

Version License Platform

It's enhanced AVURLAsset with seamless cache layer. It handles the playing of an audio/video file while streaming and simultaneuosly saving downloaded data to a local URL. FYCachedURLAsset was designed to prevent download the same bytes twice.

Installation

Manual:
Add to your project source files from FYCachedURLAsset folder

CocoaPods:
FYCachedURLAsset is available through CocoaPods. To install it, add the following line to your Podfile:

pod 'FYCachedURLAsset'

How to use

FYCachedURLAsset is a replacement for [AVURLAsset URLAssetWithURL:URL options:nil], but with additional local file path argument

NSString *cacheFilePath = [documentsPath stringByAppendingPathComponent:[URL lastPathComponent]];

FYCachedURLAsset *asset = [FYCachedURLAsset cachedURLAssetWithURL:URL cacheFilePath:cacheFilePath];

Features

  • supports streaming of media file, so it can be playbacked as soon as first data is available
  • simultaneously saves all downloaded data to a file during streaming
  • gracefully handles interruptions and resumes download only from place where was stopped
  • supports ETag header attribute to skip file download if no changes were made on the remote file from the last time
  • allows to seek stream to any place, but with limited cache support

License

FYCachedURLAsset is available under the MIT license. See the LICENSE file for more info.

Example

To run the example project, clone the repo, and run pod install from the Example directory, open workspace file and run.

screenshot screenshot