i am an amateur ios developer with version 4.6 of xcode and OSX 10.8.4. I am trying to make an app which plays sound but when i try to run the app i get this message:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* - [NSURL initFileURLWithPath:]: nil string parameter'
My app also wont launch.
Here is the code for my view controller.h:
ViewController.h:
#import <UIKit/UIKit.h>
#import <RevMobAds/RevMobAds.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
- (IBAction)playButton:(id)sender;
- (IBAction)stopButton:(id)sender;
@end
And here is my view controller.m:
Viewcontroller.m:
#import "ViewController.h"
#import <RevMobAds/RevMobAds.h>
@interface ViewController ()
{
AVAudioPlayer *avPlayer;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"98648__dobroide__20100606-mosquito" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:stringPath];
NSError *error;
avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
[avPlayer setNumberOfLoops:-1];
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playButton:(id)sender {
[avPlayer play];
}
- (IBAction)stopButton:(id)sender {
[avPlayer pause];
}
@end