我是一名业余 ios 开发人员,拥有 xcode 4.6 版和 OSX 10.8.4。我正在尝试制作一个播放声音的应用程序,但是当我尝试运行该应用程序时,我收到以下消息:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* - [NSURL initFileURLWithPath:]: nil string parameter”
我的应用程序也不会启动。
这是我的视图 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
这是我的视图控制器.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