大致UI
Paste_Image.png核心代码
-拉取网络数据
<p></p><pre><code>
func dataConfig() -> Void {
DataTools.loadNewAvData("http://c.m.163.com/nc/video/home/0-10.html"){ (news) -> Void in
guard let resultArray = news else{
return
}
self.videoNewsArray = resultArray
self.view .addSubview(self.basetableView)
self.basetableView.reloadData()
}
}
</code></pre>
-
UI布局:主要是监听播放按钮的状态
<p></p><pre><code>
func uiConfig() -> Void {
self.view.backgroundColor = UIColor.whiteColor()
self.edgesForExtendedLayout = .None
basetableView = UITableView(frame: self.view.bounds, style: .Plain)
basetableView.delegate = self
basetableView.dataSource = selfbasetableView .registerNib(UINib(nibName: "VideoCell", bundle: nil), forCellReuseIdentifier: "VideoCell") basetableView.sectionFooterHeight = 5 // 预估高度 basetableView.estimatedRowHeight = 150 basetableView.rowHeight = UITableViewAutomaticDimension automaticallyAdjustsScrollViewInsets = false NSNotificationCenter.defaultCenter().addObserver(self, selector: "playNewsVideo:", name: "PlayerButtonDidClikNotification", object: nil)
}
</code></pre>
通知实现:创建全屏的播放试图
<p></p><pre><code>
func playNewsVideo(notification:NSNotification) {
let dict = notification.userInfo
guard let urlStr = dict?["url"] as? String,
let inView = dict?["inView"] as? UIView,
let playingCell = dict?["cell"] as? VideoCell
where urlStr != playingNewsUrl else {
print("重复播放")
return
}
playingPlayerView?.removeFromSuperview()
playingPlayerView = nil
// 处理cell重用
self.playingCell = playingCell
playingCellIndexPath = basetableView.indexPathForCell(playingCell)
playingPlayerView = WLVideoPlayerView(url: NSURL(string: urlStr)!)
playingPlayerView?.customControlView = controlView
playingPlayerView?.placeholderView = UIImageView(image: UIImage(named: "302"))
playingPlayerView?.playInView(inView)
}
</code></pre>
网友评论