Hello All,
Just so you know...i've never programmed.
I've been tinkering around with Nitrex88's cat sound tutorial and i've learned alot but i can't seem to get it working.
i don't get any error's or warnings but here are my debugger results
2009-02-10 11:30:00.234 meow[10110:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
MainView.h
Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@class SoundEffect;
@interface MainView : UIView {
IBOutlet UIImageView *catImage;
SoundEffect *soundEffect;
}
@end
MainView.m
Code:
#import "MainView.h"
#import "SoundEffect.h"
@implementation MainView
-(void)awakeFromNib {
NSBundle *mainBundle = [NSBundle mainBundle];
soundEffect = [[SoundEffect alloc] initWithContentsOfFile: [mainBundle pathForResource:@"cat" ofType:@"wav"]];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[soundEffect play];
}
@end
SoundEffect.h
Code:
#import "MainView.h"
#import "SoundEffect.h"
@implementation MainView
-(void)awakeFromNib {
NSBundle *mainBundle = [NSBundle mainBundle];
soundEffect = [[SoundEffect alloc] initWithContentsOfFile: [mainBundle pathForResource:@"cat" ofType:@"wav"]];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[soundEffect play];
}
@end
SoundEffect.m
Code:
#import "SoundEffect.h";
@implementation SoundEffect
// Creates a sound effect object from the specified sound file
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath {
if (aPath) {
return [[[SoundEffect alloc] initWithContentsOfFile:aPath] autorelease];
}
return nil;
}
// Initializes a sound effect object with the contents of the specified sound file
- (id)initWithContentsOfFile:(NSString *)path {
self = [super init];
// Gets the file located at the specified path.
if (self != nil) {
NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
// If the file exists, calls Core Audio to create a system sound ID.
if (aFileURL != nil) {
SystemSoundID aSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
if (error == kAudioServicesNoError) { // success
_soundID = aSoundID;
} else {
NSLog(@"Error %d loading sound at path: %@", error, path);
[self release], self = nil;
}
} else {
NSLog(@"NSURL is nil for path: %@", path);
[self release], self = nil;
}
}
return self;
}
// Releases resouces when no longer needed.
-(void)dealloc {
AudioServicesDisposeSystemSoundID(_soundID);
[super dealloc];
}
// Plays the sound associated with a sound effect object.
-(void)play {
// Calls Core Audio to play the sound for the specified sound ID.
AudioServicesPlaySystemSound(_soundID);
}
@end
any help would be appreciated.
Thanks in advance!