源文 http://www.jianshu.com/p/9b754b62620d
AVPlayer之视频
使用AVPlayer播放视频必须知道的三个类
1.1 AVPlayer : 理解成播放器
1.2 AVPlayerItem : 播放器需要播放的资源,比如一首歌曲
1.3 AVPlayerLayer : 要显示视频我们就要把AVPlayerLayer对象加到要显示的视图的layer层上,因此我们只要能拿到AVPlayer的layer,然后把拿到的layer 赋值给 AVPlayerLayer对象即可
视频播放示例
控制器.M中
@property (nonatomic, strong) AVPlayer * player;
@property (nonatomic, strong) AVPlayerLayer *playerLayer;
@property (nonatomic, strong) AVPlayerItem *playerItem;
@property (nonatomic ,strong) PlayerView *playerView;
//初始化播放器
- (AVPlayer *)player
{
if (!_player) {
_player = [AVPlayer playerWithPlayerItem:self.playerItem];
}
return _player;
}
1.上面的PlayerView是自定义类,继承UIView,在.h中声明一个avplayer就可以了
2.也可以直接在控制器的M中把PlayerView *playerView 中类改为UIView
网友评论