本文介绍了(NSURL *)sound_url中的空格无法播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想播放这样的声音:
#define url(x) [NSURL URLWithString:x]
....
AVAudioPlayer *myFatBeat;
myFatBeat = [[AVAudioPlayer alloc] initWithContentsOfURL:url(@"/Library/Ringtones/Bell% Tower.m4r") error:nil];
[myFatBeat setNumberOfLoops:-1];
[myFatBeat play];
但是失败.我认为这是由于Bell
和Tower
之间的空格所致,如果声音名称为Àlarm
则可以正常工作.然后,我尝试转义类似Bell\ Tower
这样的声音名称,但是在编译时却得到了error: unknown escape sequence: '\040'
.
but it fails. I think it's due to the space between Bell
and Tower
, as it works if the sound name is Àlarm
. Then, I tried to escape the sound name like this Bell\ Tower
, but I get error: unknown escape sequence: '\040'
when compiling.
有什么想法吗?
推荐答案
我忘记了这是否是您在NSUrl
中执行的操作,但是您可以尝试使用%20
代替空格.
I forgot if this is how you do it in an NSUrl
, but you can try %20
instead of the space.
myFatBeat = [[AVAudioPlayer alloc]
initWithContentsOfURL:url(@"/Library/Ringtones/Bell%20Tower.m4r") error:nil];
这篇关于(NSURL *)sound_url中的空格无法播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!