iOS 类似网易视频播放

大致UI

iOS 类似网易视频播放_第1张图片
Paste_Image.png

核心代码

-拉取网络数据


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()
        
    }

}

  • UI布局:主要是监听播放按钮的状态


    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)
    

    }


    通知实现:创建全屏的播放试图


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)

}

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

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

你可能感兴趣的:(iOS 类似网易视频播放)