AVPlayerViewController简介

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

1.导入头文件
#import 
#import 
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简介)