开发者

initFileURLWithPath:(NSString)] returns null

开发者 https://www.devze.com 2023-01-03 08:08 出处:网络
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@\"Opening\" ofType:@\"wav\"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: so开发者_如何学PythonundFilePath];
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号