前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS 使用AVPlayer播放MP4

IOS 使用AVPlayer播放MP4

作者头像
用户5760343
发布2019-07-08 12:49:29
2.6K0
发布2019-07-08 12:49:29
举报
文章被收录于专栏:sktj
代码语言:javascript
复制
 1 import UIKit
 2 import AVFoundation
 3
 4 class ViewController:UIViewController {
 5
 6 override func viewDidLoad() {
 7 super.viewDidLoad()
 8 // Do any additional setup after loading the view,
 typically from a nib.
 9 let moviePath =
 Bundle.main.path(forResource:“movie”, ofType:“mp4”)
 10 let movieURL = URL(fileURLWithPath:moviePath!)
 11
 12 let avPlayer = AVPlayer(url:movieURL as URL)
 13 let avPlayerLayer = AVPlayerLayer(player:avPlayer)
 14 avPlayerLayer.frame = self.view.bounds
 15 avPlayerLayer.videoGravity =
 AVLayerVideoGravityResizeAspectFill
 16 self.view.layer.addSublayer(avPlayerLayer)
 17
 18 avPlayer.play()
 19 }
 20 }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.06.10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档