视频的播放

#import "ViewController.h"#import#import#import@interface ViewController ()

/* 不带界面播放视频 */

@property (strong, nonatomic) MPMoviePlayerController *playerC;

/* AVPlayerViewController */

@property (strong, nonatomic) AVPlayerViewController *playerVC;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

// 带界面

- (IBAction)playWithView

{

// 加载本地资源

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Alizee_La_Isla_Bonita.mp4" withExtension:nil];

// 使用带界面的控制器

MPMoviePlayerViewController *playerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

// 弹出控制器

[self presentViewController:playerVC animated:YES completion:nil];

}

- (IBAction)play

{

// 加载本地资源

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Alizee_La_Isla_Bonita.mp4" withExtension:nil];

//    // 创建控制器

//    MPMoviePlayerController *playerC = [[MPMoviePlayerController alloc] initWithContentURL:url];

//    self.playerC = playerC;

//    // 设置界面大小

//    playerC.view.frame = CGRectMake(0, 0, 200, 300);

//    // 添加界面

//    [self.view addSubview:playerC.view];

//

//    // 播放

//    [playerC play];

// iOS9方法

AVPlayerViewController *playerVC = [[AVPlayerViewController alloc] init];

self.playerVC = playerVC;

// 创建播放器

playerVC.player = [AVPlayer playerWithURL:url];

// 设置界面大小

playerVC.view.frame = CGRectMake(0, 0, 300, 400);

// 添加界面

[self.view addSubview:playerVC.view];

// 播放

[playerVC.player play];

}

@end

你可能感兴趣的:(视频的播放)