远程视频播放
单纯的播放, 没有控制UI, 而且如果要显示播放界面, 需要借助AVPlayerLayer, 添加图层到需要展示的图层上
AVPlayer中的MVC
1、v层 :AVPlayerLayer
2、m层 :AVPlayerItem
3、c层 :AVPlayer
-(AVPlayer *)player
{
if (!_player) {
NSURL *remoteURL = [NSURL URLWithString:@"http://ips.ifeng.com/video.ifeng.com/video04/2011/03/24/480x360_offline20110324.mp4"];
_player = [AVPlayer playerWithURL:remoteURL];
}
return _player;
}
- (void)viewDidLoad
{
// 1. 根据player对象, 创建 AVPlayerLayer 对象
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
// 2. 设置图层 AVPlayerLayer 的大小
layer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height * 9 / 16);
// 3. 添加到需要展示的视图上即可
[self.view.layer addSublayer:layer];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.player play];
}
网友评论