我的视频内容有问题。我想从我的viewcontroller加载视频,我收到此错误: [NSURL initFileURLWithPath:]:nil字符串参数 当我尝试从网址加载视频时,视频无法显示。
我确信我的变量targetURN不是nil。
从这里我加载了我的viewcontroller:
- (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];
}
在我的viewcontroller中:
- (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];
}
}
答案 0 :(得分:0)
您是否尝试过首先分配网址?
NSURL *vidURL = [[NSURL alloc] initWithString:self.targetURN];
作为一般建议,请始终尝试使用self.targetURN
,或将其同步到其他名称,例如
@synchronize targetURN = _targetURN
然后在您的代码中使用_targetURN
。这可以确保您(无论如何)使用正确的属性。
(当然这适用于所有属性)
答案 1 :(得分:0)
我通过添加此行来解决错误部分
NSString *urlString = [NSString stringWithFormat:url];
- (void)openVideoView:(NSString *)url{
NSString *urlString = [NSString stringWithFormat:url];
IDPVideoView *vv = [[IDPVideoView alloc] initWithURN:url];
[self presentModalViewController:vv animated:NO];
}
但视频仍未显示。