ViewController.h文件中添加如下代码:
#import <MediaPlayer/MediaPlayer.h>
@property(nonatomic,retain) MPMoviePlayerController *movieController;//添加movieController的属性
ViewController.m文件中添加如下代码:
1 @synthesize movieController;//合成movieController,自动生成set,get方法 2 NSURL *videoUrl = [[NSBundle mainBundle]URLForResource:@"clear" withExtension:@"mp4"];//定位资源clear.mp4 3 movieController = [[MPMoviePlayerController alloc]initWithContentURL:videoUrl];//初始化movieController 4 [movieController.view setFrame:self.view.bounds];//movieController视图的大小 5 [movieController setRepeatMode:MPMovieRepeatModeOne];//重复方式 6 [movieController setScalingMode:MPMovieScalingModeAspectFill];//缩放方式满屏 7 [movieController play];//播放 8 [self.view addSubview:movieController.view];//添加