2012-06-22 72 views
0

我正在使用Xcode 4.3,並且播放聲音時出現問題... 我從我在這裏找到的答案下載了該項目,但是當我將其文件更改爲http://dl.dropbox.com/u/63377498/AudioText.zip時,我可以聽不到任何聲音。可以是我的模擬器的問題?我的Mac的設置?我不知道...... 這是我使用的代碼:無法在Xcode 4.3上播放聲音

@interface ViewController() 
@property (nonatomic, strong) AVAudioPlayer *theAudio; 
@end 

@implementation ViewController 
@synthesize theAudio = _theAudio; 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

// Do any additional setup after loading the view, typically from a nib. 
NSString *soundPath =[[NSBundle mainBundle] pathForResource:@"sad" ofType:@"caf"]; 
NSURL *soundURL = [NSURL fileURLWithPath:soundPath]; 

NSError *error; 
self.theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error]; 
} 

- (IBAction)pushBell { 
[self.theAudio play]; 
} 
+0

我發現我的聲音文件有問題,但我不知道爲什麼我有這個問題。我試圖用另一種聲音來改變聲音文件,它工作。 – arniotaki

+0

除非聲音文件由[Django Reinhardt](http://en.wikipedia.org/wiki/Django_Reinhardt)編寫,否則這不需要與Django模型。刪除標籤。 –

回答

0

終於讓我找到我自己的答案。我一切正常,但我用mp3格式從YouTube上下載了一個聲音文件,並通過更改擴展名將其轉換爲.caf格式。這就是爲什麼我無法播放該聲音的原因!