NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Opening" ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: so开发者_如何学PythonundFilePath];
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?
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.
精彩评论