{"id":13908626,"url":"https://github.com/ustwo/videoplayback-ios","last_synced_at":"2025-08-05T16:10:27.344Z","repository":{"id":56925961,"uuid":"88890074","full_name":"ustwo/videoplayback-ios","owner":"ustwo","description":"Swift AVPlayer wrapper using the VIPER architecture. Currently a work in progress ","archived":false,"fork":false,"pushed_at":"2019-05-21T14:31:03.000Z","size":90369,"stargazers_count":216,"open_issues_count":5,"forks_count":26,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-11T07:57:56.118Z","etag":null,"topics":["avplayer","ios","ios-swift","modules","swift","video","video-feed","viper","viper-architecture","viper-modules","viper-pattern-architecture"],"latest_commit_sha":null,"homepage":"https://ustwo.com/blog/ins-and-outs-of-viper","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/ustwo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-20T16:59:58.000Z","updated_at":"2025-03-05T12:03:42.000Z","dependencies_parsed_at":"2022-08-21T04:20:48.375Z","dependency_job_id":null,"html_url":"https://github.com/ustwo/videoplayback-ios","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustwo%2Fvideoplayback-ios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustwo%2Fvideoplayback-ios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustwo%2Fvideoplayback-ios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustwo%2Fvideoplayback-ios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ustwo","download_url":"https://codeload.github.com/ustwo/videoplayback-ios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253534747,"owners_count":21923541,"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":["avplayer","ios","ios-swift","modules","swift","video","video-feed","viper","viper-architecture","viper-modules","viper-pattern-architecture"],"created_at":"2024-08-06T23:02:52.446Z","updated_at":"2025-05-11T07:58:08.691Z","avatar_url":"https://github.com/ustwo.png","language":"Swift","funding_links":[],"categories":["HarmonyOS","Swift","Players \u0026 Clients"],"sub_categories":["Windows Manager","Mobile Players"],"readme":"\u003cp align=\"center\" \u003e\n\u003cimg src=\"Images/VPKPlayback_logo.png\" title=\"VPKVideoPlayer logo\" float=left\u003e\n\u003c/p\u003e\n\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/ustwo/videoplayback-ios)\n[![pod](https://img.shields.io/badge/pod-0.2.3-green.svg)](https://github.com/ustwo/videoplayback-ios) \n[![pod](https://img.shields.io/badge/swift-support-fc2f24.svg?maxAge=2592000)](https://github.com/apple/swift)\n\n\n## Summary \n\nThis framework is built using the VIPER (modified to VIPE) architecture. It started as an experiment with the architecture itself and is now a work in progress.\n\nIt is a swift wrapper around the AVFoundation framework. Use it to play remote, or local videos in a simple view or feed. Its purpose is to make playing progressive downloads and live streams simpler in your iOS applications\n\nWe also wrote a blog post on VIPER itself here: https://ustwo.com/blog/ins-and-outs-of-viper\n\n## Disclaimer:\n\nThis framework is a work in progress. Unit tests, VIPE refactoring, and bug fixes are pending. \n\n## Features\n\n- [x] Scrub Video \n- [x] Handle play or stop video in main thread\n- [x] Play in UITableView \n- [x] Autoplay video    \n- [x] HTTPS support\n- [x] Written in Swift \n- [x] Landscape support\n- [x] Cocoapod support \n\n## Requirements\n\n- iOS 10.0 or later\n- Xcode 8.3 or later\n\n## Getting Started\n\n- Go to the \"DemoVideoPlaybackKit\" folder, run pod install. Open the workspace and build \n\n\n## About\n\nThe VIPER architecture has been talked about in the iOS community; however, it is uncommonly used. We wanted to gain an in depth understanding of this design pattern and see what the buzz was all about. As a result, we decided to test the following hypothesis: \n\n\u003e As a developer I would like to use the VIPER design pattern to build reusable modules\n\n\nWe then decided to experiment with VIPER \u0026 playing video content. Playing video involves UI updates, data downloading \u0026 data syncrhonization. These complexities \u0026 interactions proved themselves to be worthwhile candidate for a VIPER structured module. \n\n## Communication\n\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n\n## Installation\n\n- pod install 'VideoPlaybackKit'\n\n## How To Use\n\n```swift \nimport VideoPlaybackKit\n```\n\n### Play a single video in a view - add a single view to your screen which contains video content\n\n\u003cimg src=\"Images/single_video.gif\" title=\"Single Video\" float=left\u003e\n\n \n\n1. Define the Video Type (local or remote). This is the ENTITY represented in the VIPER structure\n\n```swift \nlet videoType = VPKVideoType.local(videoPathName: \"Elon_Musk\", fileType: \"mp4\", placeholderImageName: \"elon_1\")\n```\n\n2. Build the video view \n\n```swift\nVPKVideoPlaybackBuilder.vpk_buildVideoView(for: videoType, shouldAutoplay: self.shouldAutoPlay, playbackBarTheme: self.toolBarTheme) { [weak self] (videoView) in\n\n        self?.view.addSubview(videoView)\n        videoView.snp.makeConstraints({ (make) in\n        make.height.equalTo(self?.view.snp.height).dividedBy(2)\n        make.top.equalTo(self?.view.snp.top).offset(10)\n        make.left.right.equalTo(self?.view)\n    })\n}\n```\n\n### Play a video in a feed\n\n\u003cimg src=\"Images/video_feed.gif\" title=\"Video Feed\" float=left\u003e\n\n1. Create a UITabieViewCell that conforms to VPKViewInCellProtocol\n\n```swift \nclass VideoTableViewCell: UITableViewCell, VPKViewInCellProtocol {\n    static let identifier = \"VideoCell\"\n    var videoView: VPKVideoView? {\n        didSet {\n            self.setupVideoViewConstraints()\n            layoutIfNeeded()\n        }\n    }\n    \n    override func prepareForReuse() {\n        super.prepareForReuse()\n        prepareForVideoReuse() //Extension default\n    }\n}\n```\n\n2. Register cell in UIViewController, set up tableview. Add videoview to cell \n \n\n```swift \n    tableView.register(VideoTableViewCell.self, forCellReuseIdentifier: VideoTableViewCell.identifier)\n    tableView.estimatedRowHeight = 400\n    tableView.rowHeight = UITableViewAutomaticDimension\n\n    datasource.asObservable().bind(to: tableView.rx.items(cellIdentifier: VideoTableViewCell.identifier)) { index, model, cell in\n            \n        guard let cell = cell as? VideoTableViewCell else { return }\n\n        VPKVideoPlaybackBuilder.vpk_buildViewInCell(for: model, at: NSIndexPath(item: index, section: 0), completion: { [weak self] (videoView) in\n                cell.videoView = videoView\n                cell.layoutIfNeeded()\n        })}.addDisposableTo(disposeBag)\n\n        tableView.rx.setDelegate(self)\n}\n```\n\n### Autoplay Videos in a feed\n\n1. Conform to the VPKTableViewVideoPlaybackScrollable protocol \n\nImplement the following: \n\n```swift \nextension FeedViewController: VPKTableViewVideoPlaybackScrollable {\n\n    func scrollViewDidScroll(_ scrollView: UIScrollView) {\n        handleAutoplayInTopVideoCell() // default implementation\n        trackVideoViewCellScrolling() // default implementation\n    }   \n\n    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {\n        if shouldAutoplayVideos {\n            handleAutoplayInTopVideoCell()\n        }\n    }\n}\n```\n\n### Play video in feed, pre-fetch video asset data. *** Recommended especially for auto playing video in a feed ***\n\n1. Create a VPKTableViewPrefetchSynchronizer object \n\n```swift \nvideoPrefetcher = VPKTableViewPrefetchSynchronizer(videoItems: datasource.value)\n```\n\n2. Conform to the UITableViewDataSourcePrefetching tableview protocool \n\n```swift \n\ntableView.prefetchDataSource = self\n\nextension FeedViewController: UITableViewDataSourcePrefetching {\n\n    func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {\n        videoPrefetcher?.tableView(tableView, prefetchRowsAt: indexPaths)\n    }\n\n    func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {\n        videoPrefetcher?.tableView(tableView, cancelPrefetchingForRowsAt: indexPaths)\n    }\n}\n```\n\n\n## Contact：\n- Email: sonam@ustwo.com\n\n\u003cimg src=\"Images/snake.png\" title=\"Snake Body\" float=left\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustwo%2Fvideoplayback-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fustwo%2Fvideoplayback-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustwo%2Fvideoplayback-ios/lists"}