Problem while playing sound using AVAudioPlayer?

纵然是瞬间 提交于 2020-01-06 19:39:32

问题


In my app, I am playing sound from library directory.

Here sounds are stored in different folders with different naming conventions.

For example,

Folders like : Test , Test 2

Now when I try to play sound from Test, it plays sound.

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/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" // 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];

How can I solve this issue ?


回答1:


Use [NSURL fileURLWithPath:recordFile] instead of URLWithString:.



来源:https://stackoverflow.com/questions/7304803/problem-while-playing-sound-using-avaudioplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!