使用AVAudioPlayer播放声音时出现问题? [英] Problem while playing sound using AVAudioPlayer?
问题描述
在我的应用程序中,我正在从库目录播放声音。
In my app, I am playing sound from library directory.
此处声音存储在具有不同命名约定的不同文件夹中。
Here sounds are stored in different folders with different naming conventions.
例如,
文件夹如:测试
,测试2
现在,当我尝试播放来自 Test
的声音时,它会播放声音。
Now when I try to play sound from Test
, it plays sound.
但是当我尝试从测试2
播放声音时,它没有播放任何声音。
But when I try to play sound from Test 2
, It is not playing any sound.
我使用以下代码播放声音:
I am using following code for playing sound :
recordFile:/ Users / taxsmart2 /库/应用程序支持/ iPhone模拟器/ 4.3 /应用程序/ 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/rec212:13:21.caf" // Play sound
recordFile:/ Users / taxsmart2 / Library / Application Support / iPhone Simulator / 4.3 / Applications / E2F2C422-605A-4EC7-A40A-7429A966351C / Library / List13-Test 2
/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" // Does not Playing sound
// May be because of space `Test 2`
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:recordFile] error:nil];
[player prepareToPlay];
点击按钮,我有以下代码:
And on the button click I am having following code :
[player play];
如何解决此问题?
推荐答案
使用 [NSURL fileURLWithPath:recordFile]
而不是 URLWithString:
。
这篇关于使用AVAudioPlayer播放声音时出现问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!