3

我的视频内容有问题。我想从我的视图控制器加载一个视频,我收到这个错误:[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];
    }
}
4

2 回答 2

1

您是否尝试过先分配网址?

NSURL *vidURL = [[NSURL alloc] initWithString:self.targetURN];

作为一般建议,请尝试self.targetURN一直使用,或将其同步为不同的名称,例如

@synchronize targetURN = _targetURN

然后_targetURN在您的代码中使用。这确保您(在任何情况下)使用正确的属性。

(当然这适用于您的所有财产)

于 2012-06-07T16:26:29.920 回答
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];    
}

但是视频仍然没有显示。

于 2012-06-08T07:16:06.187 回答