2010-06-09 66 views
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];    

我已經插入一個wav文件在我project.ButinitFileURLWithPath:(的NSString)返回null

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

返回null,控制檯打印:

和應用KILLS ... 有人能幫我嗎?

回答

2

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

後:

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

什麼是打印出來?如果它是「null」,那麼你的bundle的Resource目錄中沒有名爲「Opening.wav」的文件。

請確保您將該文件添加到項目中,它出現在Xcode中可執行文件目標的「Copy Bundle Resources」構建階段。