{"id":13908786,"url":"https://github.com/ZhgChgLi/ZPlayerCacher","last_synced_at":"2025-07-18T08:31:36.158Z","repository":{"id":161486965,"uuid":"612890185","full_name":"ZhgChgLi/ZPlayerCacher","owner":"ZhgChgLi","description":"ZPlayerCacher is a lightweight implementation of the AVAssetResourceLoaderDelegate protocol that enables AVPlayerItem to support caching streaming files.","archived":false,"fork":false,"pushed_at":"2025-03-11T12:25:26.000Z","size":78,"stargazers_count":25,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T21:02:23.294Z","etag":null,"topics":["audio-caching","audio-streaming","avassetresourceloaderdelegate","avfoundation","cache","caching-library","ios","resourceloader","streaming-audio","swift","video-cache"],"latest_commit_sha":null,"homepage":"https://link.zhgchg.li/","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/ZhgChgLi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"buy_me_a_coffee":"zhgchgli"}},"created_at":"2023-03-12T09:39:39.000Z","updated_at":"2025-05-09T10:46:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"8491fb28-e733-4073-bfe7-b0696a7002da","html_url":"https://github.com/ZhgChgLi/ZPlayerCacher","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ZhgChgLi/ZPlayerCacher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhgChgLi%2FZPlayerCacher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhgChgLi%2FZPlayerCacher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhgChgLi%2FZPlayerCacher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhgChgLi%2FZPlayerCacher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZhgChgLi","download_url":"https://codeload.github.com/ZhgChgLi/ZPlayerCacher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhgChgLi%2FZPlayerCacher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265728814,"owners_count":23818729,"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":["audio-caching","audio-streaming","avassetresourceloaderdelegate","avfoundation","cache","caching-library","ios","resourceloader","streaming-audio","swift","video-cache"],"created_at":"2024-08-06T23:02:59.690Z","updated_at":"2025-07-18T08:31:36.078Z","avatar_url":"https://github.com/ZhgChgLi.png","language":"Swift","funding_links":["https://buymeacoffee.com/zhgchgli","https://www.buymeacoffee.com/zhgchgli","https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20beer!\u0026emoji=%F0%9F%8D%BA\u0026slug=zhgchgli\u0026button_colour=FFDD00\u0026font_colour=000000\u0026font_family=Bree\u0026outline_colour=000000\u0026coffee_colour=ffffff"],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# ZPlayerCacher\n\n![ZPlayerCacher](https://user-images.githubusercontent.com/33706588/224538295-374df52d-c162-4ad8-9eaa-1df7ebb784bc.jpg)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://codecov.io/gh/ZhgChgLi/ZPlayerCacher\" target=\"_blank\"\u003e\u003cimg src=\"https://codecov.io/gh/ZhgChgLi/ZPlayerCacher/branch/main/graph/badge.svg?token=DtFM8tKJye\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ZhgChgLi/ZPlayerCacher/actions/workflows/ci.yml\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/ZhgChgLi/ZPlayerCacher/actions/workflows/ci.yml/badge.svg?branch=main\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nZPlayerCacher is a lightweight implementation of the AVAssetResourceLoaderDelegate protocol that enables AVPlayerItem to support caching streaming files.\n\n\u003e Please note that while this project serves as a demonstration of AVFoundation AVAssetResourceLoaderDelegate and the use of Combine to manage data flow, the code may not be written to the highest standard of cleanliness. If you have any suggestions for improving the code, please feel free to create an issue or pull request on the repository.\n\n- [Technical Detail - AVPlayer 實踐本地 Cache 功能大全](https://medium.com/zrealm-ios-dev/avplayer-%E5%AF%A6%E8%B8%90%E6%9C%AC%E5%9C%B0-cache-%E5%8A%9F%E8%83%BD%E5%A4%A7%E5%85%A8-6ce488898003)\n\n# Buy me a coffee ❤️❤️❤️\n\n\u003ca href=\"https://www.buymeacoffee.com/zhgchgli\" target=\"_blank\"\u003e\u003cimg width=\"545\" alt=\"bmc-button\" src=\"https://github.com/user-attachments/assets/5983bfc9-27fd-49e0-a7f4-eb07657c6e31\"\u003e\u003c/a\u003e\n\n[**If this project has helped you, feel free to sponsor me a cup of coffee, thank you.**](https://www.buymeacoffee.com/zhgchgli)\n\n\n## Installation\n\n### Swift Package Manager\n\n- File \u003e Swift Packages \u003e Add Package Dependency\n- Add `https://github.com/ZhgChgLi/ZPlayerCacher.git`\n- Select \"Up to Next Major\" with \"1.0.0\"\n\nor \n\n```swift\n...\ndependencies: [\n  .package(url: \"https://github.com/ZhgChgLi/ZPlayerCacher.git\", from: \"1.0.0\"),\n]\n...\n.target(\n    ...\n    dependencies: [\n        \"ZPlayerCacher\",\n    ],\n    ...\n)\n```\n\n### CocoaPods\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '13.0'\nuse_frameworks!\n\ntarget 'MyApp' do\n  pod 'ZPlayerCacher', '~\u003e 1.0.0'\nend\n```\n\n## Usage\n```swift\nlet cacher: Cacher = PINCacher() // your implementation of Local Cache policy (Cacher Protocol), ref: /Sources/ZPlayerCacher/DataFetcherStrategy/Cacher/PINCacher.md\nlet logger = DefaultPlayerCacherLogger()\nlet factory = CacheableAVURLAssetFactory(cacher: cacher, logger: logger).makeCacheableAVURLAssetIfSupported(url: url)\n\nlet playerItem = AVPlayerItem(asset: asset) // than playerItem will support caching\n\n// DefaultPlayerCacherLogger:\nclass DefaultPlayerCacherLogger: PlayerCacherLogger {\n    var loggerLevel: PlayerCacherLevel = .info\n}\n\n// PINCacher:\npublic final class PINCacher: Cacher {\n\n    static let cache: PINCache = PINCache(name: \"ResourceLoader\")\n\n    private lazy var jsonDecoder = JSONDecoder()\n    \n    public func set(key: String, data: Data, completion: ((Error?) -\u003e Void)?) {\n        PINCacher.cache.setObjectAsync(data, forKey: key, completion: nil)\n    }\n\n    public func get(key: String) -\u003e Data? {\n        let data = PINCacher.cache.object(forKey: key) as? Data\n        return data\n    }\n\n    public static func clean() {\n        PINCacher.cache.removeAllObjects()\n    }\n\n    public static func setByteLimit(memoryByteLimit: UInt, diskByteLimit: UInt) {\n        PINCacher.cache.memoryCache.costLimit = memoryByteLimit\n        PINCacher.cache.diskCache.byteLimit = diskByteLimit\n    }\n}\n\n```\n\n### Example\n- ZPlayerCacherExample/ZPlayerCacherExample.xcodeproj\n\n## Things to know\n- Due to limitations in the Apple iOS system, currently unsupported video formats such as HLS file format(.ts) are not supported by ZPlayerCacher.\n\n## Who is using\n[![pinkoi](https://user-images.githubusercontent.com/33706588/221343295-3e3831e6-f76d-430a-87e3-4daf9815297d.jpg)](https://en.pinkoi.com)\n\n[Pinkoi.com](https://en.pinkoi.com) is Asia's leading online marketplace for original design goods, digital creations, and workshop experiences.\n\n## About\n- [ZhgChg.Li](https://zhgchg.li/)\n- [ZhgChgLi's Medium](https://blog.zhgchg.li/)\n\n## Other works\n### Swift Libraries\n- [ZMarkupParser](https://github.com/ZhgChgLi/ZMarkupParser) is a pure-Swift library that helps you to convert HTML strings to NSAttributedString with customized style and tags.\n- [ZPlayerCacher](https://github.com/ZhgChgLi/ZPlayerCacher) is a lightweight implementation of the AVAssetResourceLoaderDelegate protocol that enables AVPlayerItem to support caching streaming files.\n\n### Integration Tools\n- [XCFolder](https://github.com/ZhgChgLi/XCFolder) is a powerful command-line tool that converts Xcode virtual groups into actual directories, reorganizing your project structure to align with Xcode groups and enabling seamless integration with modern Xcode project generation tools like Tuist and XcodeGen.\n- [ZReviewTender](https://github.com/ZhgChgLi/ZReviewTender) is a tool for fetching app reviews from the App Store and Google Play Console and integrating them into your workflow.\n- [ZMediumToMarkdown](https://github.com/ZhgChgLi/ZMediumToMarkdown) is a powerful tool that allows you to effortlessly download and convert your Medium posts to Markdown format.\n- [linkyee](https://github.com/ZhgChgLi/linkyee) is a fully customized, open-source LinkTree alternative deployed directly on GitHub Pages.\n\n# Donate\n\n[![Buy Me A Coffe](https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20beer!\u0026emoji=%F0%9F%8D%BA\u0026slug=zhgchgli\u0026button_colour=FFDD00\u0026font_colour=000000\u0026font_family=Bree\u0026outline_colour=000000\u0026coffee_colour=ffffff)](https://www.buymeacoffee.com/zhgchgli)\n\nIf you find this library helpful, please consider starring the repo or recommending it to your friends.\n\nFeel free to open an issue or submit a fix/contribution via pull request. :)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FZhgChgLi%2FZPlayerCacher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FZhgChgLi%2FZPlayerCacher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FZhgChgLi%2FZPlayerCacher/lists"}