1

我是 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

这段代码有什么错误?请告诉我。

4

2 回答 2

1

`NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"你的音频文件名" ofType:@"wav"]];

AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];

[点击播放];`

于 2012-12-18T15:11:36.453 回答
0

名称与上一个不匹配有一个额外的空间,在 ios上编码

a) 2012-12-18 13:50:56 +0000.caf
b) 2012-12-18 13:50:56%20+0000.caf

于 2012-12-18T14:15:56.900 回答