MPMoviePlayerController视频播放

需要包含头文件 #import MediaPlayer.framework

#import 
@property (nonatomic,strong) MPMoviePlayerController *player;

// 本地视频
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
self.player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:videoPath]];
// 网络视频使用
// NSURL*videoPath = [NSURL URLWithString:@"http://www.xxx.com/1.mp4"]
self.player.view.frame = self.view.frame;
[self.view addSubview:self.player.view];
// 不需要进度条
self.player.controlStyle = MPMovieControlStyleNone;
// 是否自动播放(默认为YES)
self.player.shouldAutoplay = YES;
// 播放本地视频时需要
self.player.movieSourceType = MPMovieSourceTypeFile;
// 开始播放
[self.player play];

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