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).
To run the example project, clone the repo, and run pod install
from the Example directory first.
VideoLibrary is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'VideoLibrary'
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()
}
...
}
- Create UIViewController subclass (I recommend to create base UIViewController subclass for all controllers which support videos. Smth like VideoViewController)
- Add VideoViewController protocol and videoController property to your subclass
class ViewController: UIViewController, VideoViewController ... {
let videoController = VideoController()
...
}
- 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)
}
- 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()
}
- 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)
}
BozhkoAlexander, [email protected]
VideoLibrary is available under the MIT license. See the LICENSE file for more info.