0

在我的应用程序中,我想在 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];
4

1 回答 1

0

您应该使用方法“presentMoviePlayerViewControllerAnimated:”:

[self presentMoviePlayerViewControllerAnimated:self.player];
于 2013-10-09T16:49:54.980 回答