Smek
Smek

Reputation: 1208

IOS [NSURL initFileURLWithPath:]: nil string parameter on loading video

I have a problem with my video content. I want to load a video from my viewcontroller and I get this error: [NSURL initFileURLWithPath:]: nil string parameter When I try to load the video from a url the video wont show up.

I am sure that my variable targetURN is not nil.

From here I load my 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];    
}

In my 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];
    }
}

Upvotes: 3

Views: 4778

Answers (2)

Smek
Smek

Reputation: 1208

I solved the error part by adding this line

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];    
}

But the video is still not showing up.

Upvotes: 0

Sebastian Flückiger
Sebastian Flückiger

Reputation: 5555

have you tried allocating the url first?

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

as a general advice, try using self.targetURN all the time, or synchronize it to a different name like

@synchronize targetURN = _targetURN

and then use _targetURN in your code.this makes sure that you (in any case) use the right property.

(of course this goes for all your properties)

Upvotes: 1

Related Questions