Ios 电影播放错误-零字符串
我试图在ios上播放一部电影,但总是出错 我的代码:Ios 电影播放错误-零字符串,ios,objective-c,mpmovieplayercontroller,Ios,Objective C,Mpmovieplayercontroller,我试图在ios上播放一部电影,但总是出错 我的代码: -(IBAction)playMovie:(id)sender NSString *filepath = [[NSBundle mainBundle] pathForResource:@"big-buck-bunny-clip" ofType:@"m4v"]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; MPMoviePlayerController *mov
-(IBAction)playMovie:(id)sender
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"big-buck-bunny-clip" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
}
错误是:
由于未捕获异常而终止应用程序
“NSInvalidArgumentException”,原因:“***-[NSURL
initFileURLWithPath::nil字符串参数'
好的,我知道了。。我忘了在构建阶段添加文件 您应该添加更明确的细节,使其成为正确的答案。
- (void)moviePlaybackComplete:(NSNotification *)notification
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];
[self.view addSubview:moviePlayerController.view];
//moviePlayerController.fullscreen = YES;
[moviePlayerController play];