Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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];
    }
}
like image 506
Smek Avatar asked Jun 21 '26 15:06

Smek


1 Answers

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)

like image 170
Sebastian Flückiger Avatar answered Jun 24 '26 04:06

Sebastian Flückiger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!