我是斯威夫特家伙回去做一些Objc工作,我想一个声音添加到我的应用程序,问题在于,path
是null
试图找到时文件定位音频文件的目标C发挥
该文件位于myProj/Resources/Sounds/genericButtonPress.wav
NSString *path = [[NSBundle mainBundle] pathForResource:@"myProj/Resources/Sounds/genericButtonPress" ofType:@"wav"];
NSLog(@"%@", path); // NULL
NSURL *url = [NSURL fileURLWithPath:path];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:NULL];
[player play];
从文档,它看起来像pathForResource
必须是绝对的,但我也试图与刚刚genericButtonPress
为我的字符串。
想在这里得到一些帮助。谢谢!
您是否试过'NSString * path = [[NSBundle mainBundle] pathForResource:@“genericButtonPress”ofType:@“wav”];'? –
我做到了。没有运气。 –
对于你的问题,你说'wav'文件名是'mysound'。但是在你的代码中你正在寻找'genericButtonPress'。你确定你没有使用错误的名字吗?尝试'NSString * path = [[NSBundle mainBundle] pathForResource:@“myProj/Resources/Sounds/mysound”ofType:@“wav”];'。 –