iPad 视网膜能够显示 1080p 视频内容。这种格式与各种分辨率兼容,但最典型的定义为 1920 x 1080。这也是使用内置相机拍摄的视频的大小,因此很明显它可以播放,并且比文档中描述的要大可接受的尺寸。
我能够使用以下代码验证这一点。创建一个基本的单视图项目并将视频文件添加到 Supporting Files 组。
视图控制器.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface CDTViewController : UIViewController{
MPMoviePlayerController *moviePlayer;
}
-(IBAction) playMovie;
@end
视图控制器.m
@implementation CDTViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)playMovie {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"IMG_3803" ofType:@"MOV"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
if ([moviePlayer respondsToSelector:@selector(loadState)]) {
[moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[moviePlayer setFullscreen:NO];
[moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
}
}
- (void)moviePlayerLoadStateDidChange:(NSNotification *)notification {
if ([moviePlayer loadState] == MPMovieLoadStateStalled) {
//handle stall
} else if([moviePlayer loadState] != MPMovieLoadStateUnknown) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[[moviePlayer view] setFrame:self.view.bounds];
[[self view] addSubview:[moviePlayer view]];
[moviePlayer play];
}
}
@end
不要忘记将 MediaPlayer.framework 添加到您的项目中。此示例假定 xib 文件中有一个播放按钮,它的 touchUpInside 事件附加到 playMovie IBAction。