2012-12-18 66 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

相关问题