仿QQ登陆界面播放动画

#pragma mark – 懒加载AVPlayer

– (AVPlayer *)player

{

if (!_player) {

//1 创建一个播放item

NSString *path = [[NSBundle mainBundle]pathForResource:@”register_guide_video.mp4″ ofType:nil];

NSURL *url = [NSURL fileURLWithPath:path];

AVPlayerItem *playItem = [AVPlayerItem playerItemWithURL:url];

// 2 播放的设置

_player = [AVPlayer playerWithPlayerItem:playItem];

_player.actionAtItemEnd = AVPlayerActionAtItemEndNone;// 永不暂停

// 3 将图层嵌入到0层

AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_player];

layer.frame = self.view.bounds;

[self.view.layer insertSublayer:layer atIndex:0];

// 4 播放到头循环播放

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playToEnd) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];

}

return _player;

}

– (void)playToEnd

{

// 重头再来

[self.player seekToTime:kCMTimeZero];

}

– (void)viewWillAppear:(BOOL)animated

{

//视频播放

[self.player play];

}

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注