ProjectBySwift-03-PlayLocalVideo

来源:互联网 发布:excel2007数据透视表 编辑:程序博客网 时间:2024/06/11 20:04

朋友看到我的文章说有点乱,所以我改了一下风格…

第三个Swift小练习
写这篇博客的目的:总结内容,记录学习;
【说明】:
1.该系列Swift项目联系均来自gitHub上一位大牛的贡献:https://github.com/allenwong/30DaysofSwift;
2.如果任何不对或者不适合的地方请多多指教。

项目介绍

1.【功能】
视频列表展示;点击某一视频进行播放
2.【使用】
UITableView,AVPlayerViewController,AVPlayer
3.【展示】
这里写图片描述
这里写图片描述

知识点介绍

1.【导入框架】Swift默认是导入UIkit框架的,当你需要使用其他框架下的内容,比如AVPlayerViewController,你需要import AVKit。比如AVPlayer,你需要import AVFoundation。
2.【注册自定义cell】

        tableView?.register(UINib.init(nibName: "VideoCell", bundle: nil), forCellReuseIdentifier: "ZYVideoCell")

3.【绘制cell】

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        let cell = tableView.dequeueReusableCell(withIdentifier: "ZYVideoCell", for: indexPath) as! VideoCell        cell.backImgView.image = UIImage(named: imgNameArr[indexPath.row])        return cell    }

4.【获取本地视频文件并播放】

let filePath = Bundle.main.path(forResource: "emoji zone", ofType: "mp4")let videoURL = URL(fileURLWithPath: filePath!)player = AVPlayer(url: videoURL)playerVC = AVPlayerViewController()playerVC?.player = player  navigationController?.pushViewController(playerVC!, animated: true)

6.【项目链接】https://github.com/codeByLemon/PlayLocalVideo

写着三个项目的感受:
1.写Swift的逻辑和OC一样,只是语法不同,你甚至可以根据OC的方法来确定并推测Swift某函数或属性的写法;
感觉OC基础还是不扎实,加油吧,菇娘。