tags:

views:

119

answers:

1
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Opening" ofType:@"wav"];     
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
NSLog(@"@ajay");         
AVAudioPlayer *audioPlayer =
        [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

[fileURL release];
[audioPlayer play];            

i have inserted a wav file in my project.But

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

returns NULL and console prints following:

and application KILLS... Can someone help me?

+2  A: 

Put

NSLog(@"soundFilePath: %@", soundFilePath);

After:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Opening" ofType:@"wav"];   

What is printed out? If it is "null" then you do not have a file named "Opening.wav" in your bundle's Resource directory.

Make sure that you add that file to your project, and it appears in a "Copy Bundle Resources" build phase in your executable's target in Xcode.

Lyndsey Ferguson