Why is path to movie file in app bundle nil?

I am trying to play a local movie in my app when a button is pressed. However when I press the button I get the following error and the app crashes.

‘NSInvalidArgumentException’, reason: ‘*** -[NSURL initFileURLWithPath:]: nil string parameter’

Here is the code I use to play the movie.

NSString *path=[[NSBundle mainBundle]pathForResource:@"koi swimming"   ofType:@"m4v"];
NSURL *url = [NSURL fileURLWithPath:path];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.view.frame = self.view.bounds;
[self.view addSubview:controller.view];
[controller.player play];

and I am attaching an image of my bundle file structure.

image of file structure

Could someone help be with getting this to play please?

Expanded images file.

images file expanded

  • Update the screenshot from Xcode with that “images” folder expanded so we can see the m4v file in the tree. Make sure the filename exactly matches, including case. Be sure the file is selected for your target.

    – 

  • Not sure I understand file is selected for your target.

    – 

  • On the Xcode menu select View -> Inspectors -> File. Then select the m4v file. Look at the “Target Membership” section of the file inspector and make sure the checkbox for your target is checked.

    – 

Leave a Comment