框架: MediaPlayer(已经过期)
- 创建
NSString *path = [[NSBundle mainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];
- 添加到视图控制器
player.view.frame = self.view.bounds;
[self.view addSubview: player.view];
- 播放
[player play];
框架: AVPlayerViewController(9.0以后使用这个)
- 创建
// 初始化对象
AVPlayerViewController *playerVc = [[AVPlayerViewController alloc]init];
NSString *path = [[NSBundle mainBundle]pathForResource:@"Alizee_La_Isla_Bonita.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
playerVc.player = [[AVPlayer alloc]initWithURL:url];
// 显示播放回退控制
playerVc.showsPlaybackControls = YES;
playerVc.videoGravity = AVLayerVideoGravityResizeAspect;
self.playerVc = playerVc;
- 控制播放
[self presentViewController:self.playerVc animated:YES completion:nil];