https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html
(不过笔者的水平抄不了它,解构太难了)
一段简单的初始化AVPlayer的代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlString=@"gooseHouse.mp4";
self.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:urlString]];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
CGSize size = self.view.bounds.size;
layer.frame = CGRectMake(0, 0, size.width, size.height);
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[self.view.layer addSublayer: layer];
[self.player play];
}
作业要求还有Pause、Play、Progress Bar,目前还在探索中。
Sophie给的Hint是骗人的!说什么要用AVFoundation!用AVPlayer的话还需要自己写 progress bar 和 pause/play button。明明用MPMoviePlayerController会简单很多!!
关于MPMoviePlayerController的使用,请见:
http://codechen.blogspot.com/2015/07/08723-mpmovieplayercontrolleruiimagepic.html
没有评论:
发表评论