• Stars
    star
    218
  • Rank 181,805 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Swift AVPlayer wrapper using the VIPER architecture. Currently a work in progress

license pod pod

Summary

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

We also wrote a blog post on VIPER itself here: https://ustwo.com/blog/ins-and-outs-of-viper

Disclaimer:

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

Features

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

Requirements

  • 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

About

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.

Communication

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

Installation

  • 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

        self?.view.addSubview(videoView)
        videoView.snp.makeConstraints({ (make) in
        make.height.equalTo(self?.view.snp.height).dividedBy(2)
        make.top.equalTo(self?.view.snp.top).offset(10)
        make.left.right.equalTo(self?.view)
    })
}

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 {
            self.setupVideoViewConstraints()
            layoutIfNeeded()
        }
    }
    
    override func prepareForReuse() {
        super.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
                cell.layoutIfNeeded()
        })}.addDisposableTo(disposeBag)

        tableView.rx.setDelegate(self)
}

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 {
            handleAutoplayInTopVideoCell()
        }
    }
}

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)
    }
}

Contact:

More Repositories

1

ustwo.com-frontend

The New & Improved ustwo Website
JavaScript
1,818
star
2

US2FormValidator

Form validation framework for iOS.
Objective-C
593
star
3

formvalidator-swift

A framework to validate inputs of text fields and text views in a convenient way.
Swift
495
star
4

mastermind

Man in the middle testing
Python
385
star
5

clockwise

Watch face framework for Android Wear developed by ustwo
Java
345
star
6

autocluster

The code base around the cluster prototypes.
JavaScript
101
star
7

ReplayKitUnityBridge

A bridge created from iOS to Unity - exposing the Cocoa ReplayKit API. It allows you to record the screen, set a limited time for the screen to be recorded, and receive a file of the recorded session
ASP
61
star
8

vip-demo-swift

Swift sample app demonstrating VIP architecture for iOS.
Swift
49
star
9

android-boilerplate

Android Boilerplate à la ustwo
Java
42
star
10

docker-browser-sync

Docker image for BrowserSync
JavaScript
39
star
11

vip-templates-swift

Xcode templates based on https://clean-swift.com for generating Swift source code in View Interactor Presenter architecture.
Shell
32
star
12

bdd-crossplatform-apps

An ustwo guide about one way to BDD cross platform applications.
Ruby
27
star
13

clockwise-samples

Sample watch faces
Java
24
star
14

GL-2D-watchface

A light-weight library to manage and render Bitmaps in OpenGL on a watch face.
Java
20
star
15

objective-c-style-guide

The ustwo Objective-C style guide
20
star
16

US2MapperKit

JSON driven object mapper developed by ustwo
Swift
17
star
17

midi-to-philips-hue

This is a proof of concept of a set of Philips Hue lights controlled by a Behringer BCD300 MIDI controller
Ruby
16
star
18

android-coding-standards

Android Coding Standards
16
star
19

daydream-experiment

Google Daydream Experiment
C#
15
star
20

recipe-book

ustwobies love food, so they Open Source their recipes, as any sane geek would do.
15
star
21

docker-node-boilerplate

⚠️ No longer maintained ⚠️
JavaScript
10
star
22

brunel

A demonstration of organisation for an app that runs on both iOS and tvOS platforms using a unified code base. ⚠️ No longer maintained ⚠️
Swift
9
star
23

docker-sauce-connect

Builds a Sauce Labs Connect image
Makefile
9
star
24

photoshop-contrast-checker

JavaScript
8
star
25

baseviewcontroller-swift

An organizational tool for writing custom view controllers using UIKit.
Ruby
8
star
26

branded-interactions

JavaScript
7
star
27

react-native-experiment

React Native experiment for mapping of content
JavaScript
7
star
28

scout

Scout discovers apps installed on an iOS device utilising the URL scheme feature.
Objective-C
7
star
29

ibeacon-demo

Objective-C
6
star
30

US2KeyboardType

Objective-C
5
star
31

ustwoadventure

Front-end code for the Adventure website
JavaScript
5
star
32

autolayout-helper-ios

UIView helper to easily create common Auto Layout Constraints for iOS
Objective-C
4
star
33

image-color-swift

Swift
4
star
34

toolbar-keyboard-ios

UIToolbar extension to create toolbars useful for keyboards or pickers for iOS
Objective-C
4
star
35

mockingbird

A demonstration of using the Swift Package Manager and writing Swift code to run on both Linux and macOS.
Swift
3
star
36

array-remove-swift

Swift
2
star
37

xcode-snippets

Xcode Snippets
2
star
38

mongolabkit-swift

MongoLabKit is a REST client API for iOS, tvOS and watchOS written to make REST calls to a MongoLab database.
Swift
2
star
39

github-scanner

A commandline tool for scanning GitHub repositories. ⚠️ No longer maintained ⚠️
Swift
2
star
40

bench-xr-social-experiments

C#
1
star
41

ustwo-swiftui-bindings-example

Swift
1
star
42

google-docs-scripts

A collection of Google docs scripts
JavaScript
1
star
43

UIColor-US2Colors

UIColor+US2Colors category
Objective-C
1
star
44

homebrew-tools

Collection of tools ustwo development might need
Ruby
1
star
45

ios-swift-dictionaries-sample

Sample code from "Reading from a Dictionary in Swift" blog post.
Objective-C
1
star
46

docker-ansible

DEPRECATED
Makefile
1
star
47

pink-workshop-22

JavaScript
1
star
48

docker-nodejs

DEPRECATED
Makefile
1
star
49

baseview-swift

UIView subclass to abstract Base functionality for iOS
Swift
1
star
50

github-issues

A command line interface to fetch Github Issues ⚠️ No longer maintained ⚠️
Rust
1
star
51

engineering-blog

usTwo Engineering
SCSS
1
star