MPMoviePlayerController仅显示白色背景

时间:2013-10-09 16:19:11

标签: ios avfoundation mpmovieplayercontroller

在我的应用程序中我想在MPMoviePlayerController中播放视频,但是当我运行应用程序时它只向我显示一个白框。这是代码:

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Problems" ofType:@"MP4"];
NSLog(@"path: %@", moviePath);
//NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
player.view.frame = CGRectMake(0, 0, 700, 700);
player.view.backgroundColor = [UIColor whiteColor];
player.controlStyle = MPMovieControlStyleDefault;
player.shouldAutoplay = YES;
[self.detailView addSubview:player.view];
[player play];

编辑:我尝试使用此代码,并为MPMoviePlayerController添加了@property。我现在可以看到播放器,但应用程序崩溃,断点无法确定在哪里。这是代码:

self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Problems" ofType:@"MP4"]]];
[self.player.view setFrame:CGRectMake(0, 0, 320, 320)];

[self.detailView addSubview:self.player.view];
[self.player play];

1 个答案:

答案 0 :(得分:0)

您应该使用方法'presentMoviePlayerViewControllerAnimated:':

[self presentMoviePlayerViewControllerAnimated:self.player];