Skip to content

Instantly share code, notes, and snippets.

@GeekTree0101
Last active July 22, 2018 14:43
Show Gist options
  • Save GeekTree0101/94c00b40ae69f7bea5e3593aed4f9bbf to your computer and use it in GitHub Desktop.
Save GeekTree0101/94c00b40ae69f7bea5e3593aed4f9bbf to your computer and use it in GitHub Desktop.
Simple Video Feed Frame Drop Example
import AsyncDisplayKit
class VideoFeedController: ASViewController<ASTableNode>, ASTableDataSource {
required init() {
super.init(node: ASTableNode.init(style: .plain))
self.node.dataSource = self
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func numberOfSections(in tableNode: ASTableNode) -> Int {
return 1
}
func tableNode(_ tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int {
return 100
}
func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) -> ASCellNodeBlock {
return {
return VideoCellNode()
}
}
}
class VideoCellNode: ASCellNode {
let videoNode = ASVideoNode.init()
let url: URL = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8")!
override init() {
super.init()
self.automaticallyManagesSubnodes = true
self.selectionStyle = .none
videoNode.backgroundColor = .black
videoNode.shouldAutorepeat = true
videoNode.shouldAutoplay = true
}
override func didLoad() {
super.didLoad()
// setAsset MainThread Only
self.videoNode.asset = AVAsset.init(url: url)
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let videoRatioLayout = ASRatioLayoutSpec.init(ratio: 0.5, child: videoNode)
let insets: UIEdgeInsets = .init(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
return ASInsetLayoutSpec.init(insets: insets, child: videoRatioLayout)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment