Giter VIP home page Giter VIP logo

videolibrary's Introduction

VideoLibrary

CI Status Version License Platform

The library is served to implement auto playable videos in a list (smth between Instagram and Facebook implementation). The point in this implementation is videos can be auto playable and non-auto playable (usual videos with play button).

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

VideoLibrary is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'VideoLibrary'

Implementation

Change your AppDelegate.swift

Add following code in your app delegate

import VideoLibrary

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    ...
    
    func applicationWillResignActive(_ application: UIApplication) {
        Video.shared.resignActive()
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
        Video.shared.didBecomeActive()
    }
    
    ...
}

Implement videos support for UIVIewControll subclass

  1. Create UIViewController subclass (I recommend to create base UIViewController subclass for all controllers which support videos. Smth like VideoViewController)
  2. Add VideoViewController protocol and videoController property to your subclass
class ViewController: UIViewController, VideoViewController ... {

    let videoController = VideoController()

...
}
  1. Connect your collection view with video controller in viewDidLoad method (or in any other place where you want to enable video support)
override func viewDidLoad() {
    super.viewDidLoad()

    videoController.setupCollectionView(self.view.collectionView)
}
  1. Call sync method at least in viewDidAppear method. You should call it on any other place where you need to resync videos in list
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    videoController.sync()
}
  1. You have to call some methods in your UICollectionViewDelegate and UIScrollViewDelegate
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    videoController.scrollViewDidEndDragging(scrollView, willDecelerate: decelerate)
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    videoController.scrollViewDidEndDecelerating(scrollView)
}

func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    videoController.collectionView(collectionView, didEndDisplaying: cell, forItemAt: indexPath)
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    videoController.collectionView(collectionView, didSelectItemAt: indexPath)
}

Author

BozhkoAlexander, [email protected]

License

VideoLibrary is available under the MIT license. See the LICENSE file for more info.

videolibrary's People

Contributors

bozhkoalexander avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.