赞
踩
#import <AVFoundation/AVFoundation.h>
-(AVPlayer *)player
{
if(_palyer == nil){
// 1.获取本地URL方式一
NSString *filePath = [NSBundle mainBundle] pathForResource:@"welcome" ofType:@"mp4"];
NSString *fileUrl = [NSURL fileURLWithPath:thePath];
// 2.获取本地URL方式二
NSURL *url = [[NSBundle mainBundle] URLForResource:@"welcome.mp4" wihtExtension:nil];
// 3.获取远程URL方式
NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"];
// 4.创建AVPlayerItem
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
// 5.创建AVPlayer
_player = [AVPlayer playerWithPlayerItem:item];
// 6.添加AVPlayerLayer
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
layer.frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.width *9 /16);
[self.view.layer addSublayer:layer];
}
return _player;
}
[[NSNotificationCenter defaultCenter] addObserver: selector:@selector(回调方法) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。