MPMoviePlayerController 仅显示白色背景
Posted
技术标签:
【中文标题】MPMoviePlayerController 仅显示白色背景【英文标题】:MPMoviePlayerController showing white background only 【发布时间】:2013-10-09 16:19:11 【问题描述】:在我的应用程序中,我想在 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】:你应该使用方法'presentMoviePlayerViewControllerAnimated:':
[self presentMoviePlayerViewControllerAnimated:self.player];
【讨论】:
以上是关于MPMoviePlayerController 仅显示白色背景的主要内容,如果未能解决你的问题,请参考以下文章
MPMoviePlayerController 仅显示黑屏 - Swift
如何在隐藏控件时仅捕获 MPMoviePlayerController 视图上的单击/点击?
设置 MPMoviePlayerController 的方向
MPMoviePlayerController 全屏方向问题