AVPlayerItem *avPlayerItem;
AVPlayer *avPlayer;
AVPlayerLayer *avPlayerLayer;
NSString *file = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"];
if (file == nil)
{
[self moviePlayFinish];
return;
}
NSURL *url = [NSURL fileURLWithPath:file];
avPlayerItem = [AVPlayerItem playerItemWithURL:url];
avPlayer = [AVPlayer playerWithPlayerItem:avPlayerItem];
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
avPlayerLayer.repeatCount = 1;
[window.layer addSublayer:avPlayerLayer];
[avPlayerItem seekToTime:kCMTimeZero];
[avPlayer play];
//调用
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayFinish) name:AVPlayerItemDidPlayToEndTimeNotification object:avPlayerItem];
网友评论