2012-12-18 70 views
1

我是iphone編程的新手。任何機構都告訴我,下面的代碼是用於播放錄製的聲音,但它不是播放設備中的聲音。任何機構都可以告訴我有什麼錯誤這段代碼。聲音沒有在iPhone的真實設備中播放

if(soundID) 
{ 
    AudioServicesDisposeSystemSoundID(soundID); 
} 

//Get a URL for the sound file 
NSURL *filePath = [NSURL fileURLWithPath:audiopath isDirectory:NO]; 
NSLog(@"%@",filePath); 
//Use audio sevices to create the sound 
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); 

//Use audio services to play the sound 
AudioServicesPlaySystemSound(soundID); 

在上面的代碼中,音頻路徑是語音記錄路徑。實際上,在數據庫路徑存儲這樣

/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/C974262E-7658-45EE-8E8C-290B780E7C3E/Documents/2012-12-18 13:50:56 +0000.caf 

在此之後,而我的檢索路徑是表明這樣的:

file://localhost/Users/User/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/C974262E-7658-45EE-8E8C-290B780E7C3E/Documents/2012-12-18%2013:50:56%20+0000.caf 

什麼是這個代碼錯誤了嗎?請告訴我。

回答

1

`NSURL * musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@「your audio file name」ofType:@「wav」]]; AVAudioPlayer * click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil]; [AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];

[點擊播放]`

+0

,你必須在你的項目中添加音頻框架,然後導入,在當前類。然後創建AVAudio玩家的對象。 –

0

的名稱不匹配的上一個有一個額外的空間,該空間上IOS編碼

一)2012年12月18日13時五十分56秒+ 0000.caf
B)2012-12- 18 13:50:56%20 + 0000.caf

相關問題