iOS 类似网易视频播放

大致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 = self

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

希望大家可可以提供一些建议。下面附上代码

[下载链接]https://git.oschina.net/mrj_mrj/videoPlayer.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容