{"id":19223948,"url":"https://github.com/sukov/cachingplayeritem","last_synced_at":"2025-04-05T13:04:09.312Z","repository":{"id":44601198,"uuid":"311184132","full_name":"sukov/CachingPlayerItem","owner":"sukov","description":"An AVPlayerItem subclass that lets you stream and cache media content on iOS","archived":false,"fork":false,"pushed_at":"2025-03-12T21:30:58.000Z","size":897,"stargazers_count":99,"open_issues_count":0,"forks_count":21,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T12:08:20.302Z","etag":null,"topics":["avfoundation","avplayeritem","caching-library","ios","ios-framework","media-library","resourceloader","swift","swift-library","video-library"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sukov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-09T00:33:46.000Z","updated_at":"2025-03-28T03:34:37.000Z","dependencies_parsed_at":"2024-11-08T00:32:38.113Z","dependency_job_id":"51acab64-30fd-4a3f-badd-64d1b7acb137","html_url":"https://github.com/sukov/CachingPlayerItem","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.045454545454545414","last_synced_commit":"b11eec74c330816694c908a187c684a567c3798b"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FCachingPlayerItem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FCachingPlayerItem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FCachingPlayerItem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FCachingPlayerItem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sukov","download_url":"https://codeload.github.com/sukov/CachingPlayerItem/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339154,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avfoundation","avplayeritem","caching-library","ios","ios-framework","media-library","resourceloader","swift","swift-library","video-library"],"created_at":"2024-11-09T15:09:58.643Z","updated_at":"2025-04-05T13:04:09.284Z","avatar_url":"https://github.com/sukov.png","language":"Swift","readme":"# CachingPlayerItem\n\nCachingPlayerItem is a subclass of AVPlayerItem that lets you stream and cache media content on iOS. Initial idea for this library was found [here](https://github.com/neekeetab/CachingPlayerItem).\n\n[![Version](https://img.shields.io/cocoapods/v/CachingPlayerItem.svg?style=flat)](https://cocoapods.org/pods/CachingPlayerItem)\n[![License](https://img.shields.io/cocoapods/l/CachingPlayerItem.svg?style=flat)](https://cocoapods.org/pods/CachingPlayerItem)\n[![Language Swift](https://img.shields.io/badge/Language-Swift%205.0-orange.svg?style=flat)](https://swift.org)\n[![Platform](https://img.shields.io/cocoapods/p/CachingPlayerItem.svg?style=flat)](https://cocoapods.org/pods/CachingPlayerItem)\n[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat)](https://www.swift.org/package-manager)\n\n## Features\n\n- [x] Playing and caching remote media\n- [x] Downloaded data is buffered and stored on a file, therefore you won't have any RAM memory issues\n- [x] Playing from a local file / data\n- [x] Convenient notifications through `CachingPlayerItemDelegate` delegate\n- [x] `CachingPlayerItem` is a subclass of `AVPlayerItem`, so you can use it in the same manner as `AVPlayerItem` and take the full advantage of `AVFoundation` Framework\n- [x] Configurable downloadBufferLimit / readDataLimit through `CachingPlayerItemConfiguration`\n- [x] Play remote media without caching and still make use of `CachingPlayerItemDelegate`\n- [x] [Complete Documentation](https://sukov.github.io/CachingPlayerItem/)\n\n## Requirements\n\n- iOS 10.0+ \n- Xcode 12.0+\n- Swift 5.0+\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate CachingPlayerItem into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '10.0'\nuse_frameworks!\n\ntarget '\u003cYour Target Name\u003e' do\n    pod 'CachingPlayerItem'\nend\n```\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. \n\nOnce you have your Swift package set up, adding `CachingPlayerItem` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/sukov/CachingPlayerItem.git\", from: \"2.0.2\")\n]\n```\n\n## Usage\n\n### Quick Start\n\n```Swift\nimport UIKit\nimport AVFoundation\nimport CachingPlayerItem\n\nclass ViewController: UIViewController {\n    // You need to keep a strong reference to your player.\n    var player: AVPlayer!\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n     \n        let url = URL(string: \"https://random-url.com/video.mp4\")!\n        let playerItem = CachingPlayerItem(url: url)\n        player = AVPlayer(playerItem: playerItem)\n        player.automaticallyWaitsToMinimizeStalling = false\n        player.play()\n        \n    }\n}\n```\n**From Apple docs: It's strongly recommended to set AVPlayer's property `automaticallyWaitsToMinimizeStalling` to `false`. Not doing so can lead to poor startup times for playback and poor recovery from stalls.**\n\nIf you want to cache a file without playing it, or to preload it for future playing, use `download()` method:\n```Swift\nlet playerItem = CachingPlayerItem(url: videoURL)\nplayerItem.download()\n```\nIt's fine to start playing the item while it's being downloaded.\n\n### CachingPlayerItemDelegate protocol\n\nNote: All of the methods are optional.\n\n```Swift\n@objc public protocol CachingPlayerItemDelegate {\n    // MARK: Downloading delegate methods\n\n    /// Called when the media file is fully downloaded.\n    @objc optional func playerItem(_ playerItem: CachingPlayerItem, didFinishDownloadingFileAt filePath: String)\n\n    /// Called every time a new portion of data is received.\n    @objc optional func playerItem(_ playerItem: CachingPlayerItem, didDownloadBytesSoFar bytesDownloaded: Int, outOf bytesExpected: Int)\n\n    /// Called on downloading error.\n    @objc optional func playerItem(_ playerItem: CachingPlayerItem, downloadingFailedWith error: Error)\n\n    // MARK: Playing delegate methods\n\n    /// Called after initial prebuffering is finished, means we are ready to play.\n    @objc optional func playerItemReadyToPlay(_ playerItem: CachingPlayerItem)\n\n    /// Called when the player is unable to play the data/url.\n    @objc optional func playerItemDidFailToPlay(_ playerItem: CachingPlayerItem, withError error: Error?)\n\n    /// Called when the data being downloaded did not arrive in time to continue playback.\n    @objc optional func playerItemPlaybackStalled(_ playerItem: CachingPlayerItem)\n}\n```\n\n**Important**: You are in charge for managing the downloaded local media files. In case you used an initializer that generates the filePath randomly, you will be able to retrieve it in `didFinishDownloadingFileAt` delegate method.\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Author\n\nsukov, gorjan5@hotmail.com\n\n## License\n\nCachingPlayerItem is available under the MIT license. See the LICENSE file for more info.\n\n## Known limitations\n\n- URL's must contain a file extension for the player to load properly. To get around this, a custom file extension can be specified e.g. `let playerItem = CachingPlayerItem(url: url, customFileExtension: \"mp3\")`.\n- HTTP live streaming (HLS) `M3U8` caching is not supported. You can only use `init(nonCachingURL:)` for playing M3U8.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukov%2Fcachingplayeritem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsukov%2Fcachingplayeritem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukov%2Fcachingplayeritem/lists"}