iOS 类似网易视频播放

作者: 孤独的剑客 | 来源:发表于2016-07-18 13:11 被阅读322次

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

    相关文章

      网友评论

        本文标题:iOS 类似网易视频播放

        本文链接:https://www.haomeiwen.com/subject/ffbpjttx.html