Video playback does not work - [NSURL initFileURLWithPath:]: parameter nil string

I am trying to understand why this does not work: / Each time I run the project, the application throws me an "NSInvalidArgumentException", reason: '* - [NSURL initFileURLWithPath:]: parameter nil string

I followed the tutorial (I'm pretty new to this) and it worked for him, and the code is exactly the same. Can someone explain what is happening?

.h file

#import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> #import <QuartzCore/QuartzCore.h> @interface FirstViewController : UIViewController { MPMoviePlayerViewController *playerController; } -(IBAction)playVideo; @end 

.m file

 #import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController { MPMoviePlayerController *mpc; } - (IBAction)playButton:(id)sender { NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"intro" ofType:@"MP4"]; NSURL *url = [NSURL fileURLWithPath:stringPath]; if(url != nil){ mpc = [[MPMoviePlayerController alloc]initWithContentURL:url]; [mpc setMovieSourceType:MPMovieSourceTypeFile]; [[self view]addSubview:mpc.view]; [mpc setFullscreen:YES]; [mpc play]; } else{ NSLog(@"URL not found"); } } @end 
+8
ios iphone ios6 video
source share
5 answers

The only important part of all this:

 NSString *stringPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"MP4"]; NSURL *url = [NSURL fileURLWithPath:stringPath]; 

I assume that the exception occurs on the second line. This would mean that stringPath was null, which would happen if the intro.MP4 file was not actually in your application.

Make sure that:

  • the file exists in your copy of the source code

  • your Xcode project has a link to this file (if it is red, then the file is actually not present)

  • For your purpose in Xcode, review the “Build Phases” and show the build phase of “Copy Bundle Resources”. This file must be present. If not, click the + button and select it.

+33
source share

Kurt’s answer worked specifically for me

“For your purpose in Xcode, look at“ Build Phases ”and show the build phase“ Copy Bundle Resources. ”This file should be present. If it is not, click the + button and select it.”

my movie file was missing. He must have been there before because he was working, and then he just stopped.

I would make a comment on Kurt's post, but did not know how to do this. I made a "voice."

+6
source share

In addition to what was mentioned in this answer https://stackoverflow.com/a/166168/ ... you also want to make sure that the file you are referencing has membership in the build target. You can specify this in the File Inspector. This answer explains how to https://stackoverflow.com/a/318960/

0
source share

Your video is too long. Using this code, the limit is 30 seconds. Your best bet is to pass it from the url. Try playing a video shorter than 30 seconds and it will work fine.

0
source share

iOS 9.2, Xcode 7.2, ARC enabled

I recently ran into this problem. Definitely do what the original authors suggest. For me it was the actual file name, which was the problem, see below ...

 NSString *pathForPuzzlePieceHitSound = [[NSBundle mainBundle] pathForResource:@"puzzle_piece_hit" ofType:@"m4a"]; NSURL *urlForPuzzlePieceHitSound = [NSURL fileURLWithPath:pathForPuzzlePieceHitSound]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)urlForPuzzlePieceHitSound, &idForPuzzlePieceHitSound); 

File name:

 @"puzzle_piece_hit" 

Does it contain characters that are illegal for naming files using this particular method. I think you can treat it and work around the problem, but it's easier to just rename the file.

After I renamed to:

 @"puzzlePieceHit" 

Everything worked fine.

Hope this helped someone! Greetings.

0
source share

All Articles