iOS-AVPlayer循环播放

2017-11-07  本文已影响116人  鱼与熊掌不能兼得

AVPlayerItem*videoItem = [[AVPlayerItemalloc] initWithURL:pathUrl];

AVPlayer*player = [AVPlayerplayerWithPlayerItem:videoItem];

player.volume =0;

AVPlayerLayer*playerLayer = [AVPlayerLayerplayerLayerWithPlayer:player];

playerLayer.backgroundColor = [UIColorwhiteColor].CGColor;

playerLayer.videoGravity =AVLayerVideoGravityResizeAspectFill;

playerLayer.frame =self.view.bounds;

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

[player play];

self.player = player;

[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotificationobject:self.player.currentItem];

- (void)dealloc {

[[NSNotificationCenterdefaultCenter] removeObserver:self];

}

// 视频循环播放

- (void)moviePlayDidEnd:(NSNotification*)notification{

AVPlayerItem*item = [notification object];

[item seekToTime:kCMTimeZero];

[self.player play];

}

上一篇下一篇

猜你喜欢

热点阅读