2015年7月5日星期日

[请勿参考][笔记][08723] AVPlayer

首先,Apple官方有一个很好的AVPlayerDemo:
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


没有评论:

发表评论