Iphone SDK:pathFoResource:Nsstring问题->播放 MP3 文件
我试图在资源文件夹中获取 10 个 mp3 文件,并在按下按钮时播放它们。我已在 NSMutableArray 中输入 mp3 文件的名称,并在按下按钮后读取每个文件。
问题是 pathForResource: 不起作用(返回 nil)。如果我明确使用文件名 - 就像 pathFoResource:@"song1.mp3" ofType:@"mp3" - 但如果我使用 pathForResource:valuem whwre valuem 是一个 NSstring,其值为 Song1
希望你能帮忙
问候
NSString *cellValue0 = [listOfmp3 objectAtIndex:anumber];
NSString *valuem;
if ( [cellValue0 length] > 0 )
valuem = [cellValue0 substringToIndex:[cellValue0 length] - 4];
NSString *pdfPath2 = [[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:pdfPath2];
I am trying to get 10 mp3 files in the resources folder and play them when a button is pressed. I have entered name of the mp3 files in a NSMutableArray and read each one after the button is pressed.
The problem is that pathForResource: is not working (returns nil). If i use the file name explicitly -like pathFoResource:@"song1.mp3" ofType:@"mp3"- but if i use pathForResource:valuem whwre valuem is an NSstring with value of song1
Hope you can help
Regards
NSString *cellValue0 = [listOfmp3 objectAtIndex:anumber];
NSString *valuem;
if ( [cellValue0 length] > 0 )
valuem = [cellValue0 substringToIndex:[cellValue0 length] - 4];
NSString *pdfPath2 = [[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:pdfPath2];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要将扩展名放在资源名称中,即
检查
valuem
不带任何扩展名。Don't put the extension in the resource name, i.e.
Check that
valuem
does not carry any extensions.对我之前的帖子感到抱歉,这里用更清晰的术语重述了问题:
弗拉基米尔:
是的,我记录了值,它给出了正确的字符串
KennyTM:
是的,这是一个错字,在原始代码中只有@“song1”,
问题是
如果我使用
但是如果我使用
它不起作用
请注意,该值是一个带有@“song1”的字符串
Sorry for my previous post, here is restatement of the problem in more clear terms:
Vladimir:
yes i log the valuem and it is giving the correct string
KennyTM:
Yes, it was a typo , in original code there is only @"song1"
the problem is that
if I use
BUT If i use
It is NOT working
note that value is a string with @"song1"