我之前没有在 iOS 中播放过视频文件,所以我不确定我是否只是遗漏了一些东西。播放器打开,但卡在加载动画中,我无法点击完成按钮。难道是我的视频文件不受支持?我为ipad编码。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *video_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
video_btn.frame = CGRectMake(0, 0, 100, 50);
[video_btn setTitle:@"Moonrise" forState:UIControlStateNormal];
[video_btn addTarget:self action:@selector(playMovie:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:video_btn];
}
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"moonrise" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我得到这个作为输出:
2012-09-25 12:47:56.206 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-09-25 12:47:56.207 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay
2012-09-25 12:47:56.221 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-09-25 12:47:56.222 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay
2012-09-25 12:47:56.226 App[4895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-09-25 12:47:56.255 App[4895:c07] [MPAVController] Autoplay: Enabling autoplay