我的视频内容有问题。我想从我的视图控制器加载一个视频,我收到这个错误:[NSURL initFileURLWithPath:]: nil string parameter 当我尝试从一个 url 加载视频时,视频不会显示。
我确信我的变量 targetURN 不为零。
从这里我加载我的视图控制器:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
[self openVideoView:@"Video"];
break;
case 1:
[self openWebview:@"About"];
break;
case 2:
[self openWebview:@"http://www.url.com"];
break;
}
}
- (void)openVideoView:(NSString *)url{
IDPVideoView *vv = [[IDPVideoView alloc] initWithURN:url];
[self presentModalViewController:vv animated:NO];
}
在我的视图控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *videoURL = nil;
if ([self.targetURN hasPrefix:@"http"])
{
videoURL = [NSURL URLWithString:targetURN];
}
else
{
videoURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:targetURN ofType:@"mp4"]];
}
if(videoURL != nil) {
MPMoviePlayerController *moviePlayer =
[[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
}