你的位置:首页 > 操作系统

[操作系统]iOS UIView上添加mp4视频


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.mp43 movieController = [[MPMoviePlayerController alloc]initWithContentURL:videoUrl];//初始化movieController4   [movieController.view setFrame:self.view.bounds];//movieController视图的大小5   [movieController setRepeatMode:MPMovieRepeatModeOne];//重复方式6   [movieController setScalingMode:MPMovieScalingModeAspectFill];//缩放方式满屏7   [movieController play];//播放8 [self.view addSubview:movieController.view];//添加

通过以上方法,就可以把视频添加到视图。