美文网首页
AVPlayerViewController简介

AVPlayerViewController简介

作者: Maggie的小蜗居 | 来源:发表于2017-01-02 20:50 被阅读112次

iOS8之后系统自带使用AVPlayerViewController来播放视频

1.导入头文件
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
2.声明属性
@property (nonatomic, strong) AVPlayer *player;
@property (nonatomic, strong) AVPlayerViewController *playerViewController;
3.实现播放代码
_player = [AVPlayer playerWithURL:[NSURL URLWithString:@"*.mp4"]]; 
_playerViewController = [[AVPlayerViewController alloc] init]; _playerViewController.player = _player;
//设置AVPlayer的填充模式
_playerViewController.videoGravity = AVLayerVideoGravityResizeAspect; 
// _playerViewController.allowsPictureInPicturePlayback = true; //画中画,iPad可用
//_playerViewController.showsPlaybackControls = true;
_playerController.view.translatesAutoresizingMaskIntoConstraints = true; //这句可以禁用自动约束,消除报错

备注:AVPlayerViewController本身支持横屏和竖屏播放

相关文章

网友评论

      本文标题:AVPlayerViewController简介

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