简述一下iOS播放视频的几种方法

一 、AVPlay

AVPlayerItem *item = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://zyvideo1.oss-cn-qingdao.aliyuncs.com/zyvd/7c/de/04ec95f4fd42d9d01f63b9683ad0"]];

self.player = [AVPlayer playerWithPlayerItem:item];

AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];

layer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * 9 / 16);

[self.view.layer addSublayer:layer];

[self.player play];

二、 MPMoviePlayerController

self.playerCon = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@"http://zyvideo1.oss-cn-qingdao.aliyuncs.com/zyvd/7c/de/04ec95f4fd42d9d01f63b9683ad0"]];

self.playerCon.view.frame = self.view.bounds;

[self.view addSubview:self.playerCon.view];

[self.playerCon play];

三、MPMoviePlayerViewController

self.playerViewCon = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:@"http://zyvideo1.oss-cn-qingdao.aliyuncs.com/zyvd/7c/de/04ec95f4fd42d9d01f63b9683ad0"]];

[self presentViewController:self.playerViewCon animated:YES completion:^{

[self.playerViewCon.moviePlayer play];

}];

四、AVPlayerViewController(iOS8以后)

AVPlayer *play = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://zyvideo1.oss-cn-qingdao.aliyuncs.com/zyvd/7c/de/04ec95f4fd42d9d01f63b9683ad0"]];

self.avPlayerViewCon = [[AVPlayerViewController alloc]init];

self.avPlayerViewCon.player = play;

self.avPlayerViewCon.allowsPictureInPicturePlayback = YES;

[self presentViewController:self.avPlayerViewCon animated:YES completion:^{

[self.avPlayerViewCon.player play];

}];

你可能感兴趣的:(简述一下iOS播放视频的几种方法)