使用 AVAudioPlayer 播放声音时出现问题?
Posted
技术标签:
【中文标题】使用 AVAudioPlayer 播放声音时出现问题?【英文标题】:Problem while playing sound using AVAudioPlayer? 【发布时间】:2011-09-05 07:07:22 【问题描述】:在我的应用程序中,我正在从库目录播放声音。
这里的声音以不同的命名约定存储在不同的文件夹中。
例如,
文件夹喜欢:Test
,Test 2
现在,当我尝试从Test
播放声音时,它会播放声音。
但是当我尝试从Test 2
播放声音时,它没有播放任何声音。
我正在使用以下代码播放声音:
recordFile : "/Users/taxsmart2/Library/Application Support/iPhone Simulator/4.3/Applications/E2F2C422-605A-4EC7-A40A-7429A966351C/Library/List13-Test/rec212:13:21.caf" // 播放声音
recordFile : "/Users/taxsmart2/Library/Application Support/iPhone Simulator/4.3/Applications/E2F2C422-605A-4EC7-A40A-7429A966351C/Library/
List13-Test 2
/rec212:13:21.caf" // 可以不播放声音
// May be because of space `Test 2`
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:recordFile] error:nil];
[player prepareToPlay];
在按钮上单击我有以下代码:
[player play];
我该如何解决这个问题?
【问题讨论】:
【参考方案1】:使用[NSURL fileURLWithPath:recordFile]
而不是URLWithString:
。
【讨论】:
以上是关于使用 AVAudioPlayer 播放声音时出现问题?的主要内容,如果未能解决你的问题,请参考以下文章
(iphone) 如何使用 AVAudioPlayer 顺序播放声音?
使用 AVAudioPlayer 播放多个声音(一个接一个)