Latest 0.2.3
License MIT
Platforms ios 10.0, requires ARC
Dependencies ASValueTrackingSlider, Alamofire, AlamofireImage, SnapKit
Authors ,




This 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.

It 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


This framework is a work in progress. Unit tests, VIPE refactoring, and bug fixes are pending.


  • [x] Scrub Video
  • [x] Handle play or stop video in main thread
  • [x] Play in UITableView
  • [x] Autoplay video
  • [x] HTTPS support
  • [x] Written in Swift
  • [x] Landscape support
  • [x] Cocoapod support


  • iOS 10.0 or later
  • Xcode 8.3 or later

Getting Started

  • Go to the "DemoVideoPlaybackKit" folder, run pod install. Open the workspace and build


The 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:

As a developer I would like to use the VIPER design pattern to build reusable modules

We then decided to experiment with VIPER & playing video content. Playing video involves UI updates, data downloading & data syncrhonization. These complexities & interactions proved themselves to be worthwhile candidate for a VIPER structured module.


  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.


  • pod install ‘VideoPlaybackKit’

How To Use

import VideoPlaybackKit

Play a single video in a view – add a single view to your screen which contains video content


  1. Define the Video Type (local or remote). This is the ENTITY represented in the VIPER structure
let videoType = VPKVideoType.local(videoPathName: "Elon_Musk", fileType: "mp4", placeholderImageName: "elon_1")
  1. Build the video view
VPKVideoPlaybackBuilder.vpk_buildVideoView(for: videoType, shouldAutoplay: self.shouldAutoPlay, playbackBarTheme: self.toolBarTheme) { [weak self] (videoView) in

        videoView.snp.makeConstraints({ (make) in

Play a video in a feed


  1. Create a UITabieViewCell that conforms to VPKViewInCellProtocol
class VideoTableViewCell: UITableViewCell, VPKViewInCellProtocol {
    static let identifier = "VideoCell"
    var videoView: VPKVideoView? {
        didSet {

    override func prepareForReuse() {
        prepareForVideoReuse() //Extension default
  1. Register cell in UIViewController, set up tableview. Add videoview to cell
    tableView.register(VideoTableViewCell.self, forCellReuseIdentifier: VideoTableViewCell.identifier)
    tableView.estimatedRowHeight = 400
    tableView.rowHeight = UITableViewAutomaticDimension

    datasource.asObservable().bind(to: tableView.rx.items(cellIdentifier: VideoTableViewCell.identifier)) { index, model, cell in

        guard let cell = cell as? VideoTableViewCell else { return }

        VPKVideoPlaybackBuilder.vpk_buildViewInCell(for: model, at: NSIndexPath(item: index, section: 0), completion: { [weak self] (videoView) in
                cell.videoView = videoView


Autoplay Videos in a feed

  1. Conform to the VPKTableViewVideoPlaybackScrollable protocol

Implement the following:

extension FeedViewController: VPKTableViewVideoPlaybackScrollable {

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        handleAutoplayInTopVideoCell() // default implementation
        trackVideoViewCellScrolling() // default implementation

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if shouldAutoplayVideos {

Play video in feed, pre-fetch video asset data. Recommended especially for auto playing video in a feed

  1. Create a VPKTableViewPrefetchSynchronizer object
videoPrefetcher = VPKTableViewPrefetchSynchronizer(videoItems: datasource.value)
  1. Conform to the UITableViewDataSourcePrefetching tableview protocool

tableView.prefetchDataSource = self

extension FeedViewController: UITableViewDataSourcePrefetching {

    func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
        videoPrefetcher?.tableView(tableView, prefetchRowsAt: indexPaths)

    func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {
        videoPrefetcher?.tableView(tableView, cancelPrefetchingForRowsAt: indexPaths)



Latest podspec

    "name": "VideoPlaybackKit",
    "version": "0.2.3",
    "summary": "Using Swift and the VIP pattern this is a module built using AVPlayer to return video views",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Sonam Dhingra": "[email protected]",
        "thoughtbot": null
    "source": {
        "git": "",
        "tag": "v0.2.3",
        "submodules": true
    "source_files": "Source/**/*.{swift,h}",
    "requires_arc": true,
    "platforms": {
        "ios": "10.0"
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3.0"
    "dependencies": {
        "ASValueTrackingSlider": [],
        "Alamofire": [
            "~> 4.4"
        "AlamofireImage": [
            "~> 3.1"
        "SnapKit": [
            "~> 3.2.0"
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This