我很困惑:
MPMoviePlayerViewController和MPMoviePlayerController
在ios6中本地播放视频的最佳方式是什么?
这是我的代码
NSURL * url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @ "17" OfType: @ "mov"]];
MoviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL: url];
[self presentMoviePlayerViewControllerAnimated: MoviePlayer];
[moviePlayer.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (moviePlayerPlaybackStateChanged :) name: MPMoviePlayerPlaybackStateDidChangeNotification object: nil];
}
-(void)moviePlayerPlaybackStateChanged:(NSNotification *)notification {
}
答案 0 :(得分:8)
MPMoviePlayerViewController用于播放全屏视频,主要用于手机。
MPMoviePlayerController可用于嵌入式视频,即不能在任何iPad上全屏显示。您需要在故事板中将空视图拖到场景中并为其指定所需大小。然后,在代码中,将电影播放器放在该子视图中。代码的第一部分应该在viewDidLoad;
中//movieplayer initialization
NSString *path = [[NSBundle mainBundle] pathForResource:@"videoName" ofType:@"m4v"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer setControlStyle:MPMovieControlStyleNone]; // for custom controls, for default controls you can leave this line out.
这部分进入viewWillAppear;
moviePlayer.repeatMode = MPMovieRepeatModeOne; // for looping
[moviePlayer.view setFrame: self.videoSuper.bounds];
[self.videoSuper addSubview: moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
其中videoSuper是故事板中添加的子视图。务必正确连接;
//in .h
@property (weak, nonatomic) IBOutlet UIView *videoSuper;