0

I am trying to create an app with my video to play in a view with a UIButton. FYI: I am using a storyboard with a tab bar view controller, so this code MPMoviePlayerView is inside another view.

I keep getting this error: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string parameter'

Here is my code:

VideoTefViewController.h

#import <UIKit/UIKit.h>

@interface VideoTefViewController : UIViewController


-(IBAction)playMovie;
@end

VideoTefViewController.m

#import "VideoTefViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTefViewController ()

@end

@implementation VideoTefViewController

-(IBAction)playMovie {

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"tef" ofType:@"mp4"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
jakife
  • 137
  • 1
  • 10

1 Answers1

0

The error is telling you that the argument to fileURLWithPath: is nil, so for some reason moviePath is nil. Are you sure you have a file called tef.mp4 in your bundle?

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I am sure I have a file called tef.mp4 in my project. It is in my Supporting Files/Resources Files folder in xcode. Should I put somewhere else? – jakife Jul 24 '12 at 11:40
  • @YuvalMarcus, try logging moviePath right after the line where you create it and see if it's nil. – rdelmar Jul 24 '12 at 15:15
  • So should I write: NSlog what? – jakife Jul 24 '12 at 23:04
  • Sorry that was a stupid question, I get this: MoviePath is: /Users/ymarcus/Library/Application Support/iPhone Simulator/5.1/Applications/A63749A0-0B7A-4E1C-93A5-93F20C89AB0D/SephardiJews.app/Tefillin.mp4, So I am guessing it is not nil – jakife Jul 24 '12 at 23:16
  • I thought you said the file was tef.mp4?, but no matter, it's obviously not nil. I don't know what to say -- I pasted your code into an app, added an mp4 file and renamed it tef, and it worked fine. Do you have somewhere else in your code where you call initFileURLWithPath: or fileURLWithPath: ? – rdelmar Jul 25 '12 at 00:37
  • No, there is nowhere else I call initFileURLWithPath or fileURLWithPath. Now, for some reason, the button doesn't give me an error and doesn't do anything, it just highlights blue for a few seconds, and I know the button is connected. I'm so confused! – jakife Jul 25 '12 at 01:01