#import "ViewController.h"#import <MediaPlayer/MediaPlayer.h>@interfaceViewController ()//声音视频播放的对象属性@property (retain)MPMoviePlayerController* player;
@end@implementationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//播放按钮
- (IBAction)btnAction:(UIButton *)sender {
NSString* path = [[NSBundle mainBundle]pathForResource:@"这里是要拖一个视频进来,填写视频名字就行了" ofType:@"mp4"];
NSURL* url = [NSURL fileURLWithPath:path];
//MPMoviePlayerController 创建视频播放器(是视图控制器)
_player = [[MPMoviePlayerController alloc]initWithContentURL:url];
//设置播放器视图大小
_player.view.frame = [UIScreen mainScreen].bounds;
[_player play];
[self.view addSubview:_player.view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
视频播放器(新)
#import "ViewController.h"//导入框架#import <AVKit/AVKit.h>#import <AVFoundation/AVFoundation.h>@interfaceViewController ()@end@implementationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)btnAction:(UIButton *)sender {
//实例化视频播放器控制器
AVPlayerViewController* player = [[AVPlayerViewController alloc]init];
//实例化视频播放器
player.player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]];
[self presentViewController:player animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end