-1

我试图在资源文件夹中获取 10 个 mp3 文件,并在按下按钮时播放它们。我在 NSMutableArray 中输入了 mp3 文件的名称,并在按下按钮后读取每个文件。

问题是 pathForResource: 不起作用(返回 nil)。如果我明确使用文件名 - 像 pathFoResource:@"song1.mp3" ofType:@"mp3"- 但如果我使用 pathForResource:valuem whwre valuem 是一个值为 song1 的 NSstring

希望你能帮忙

问候

 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];
4

2 回答 2

2

不要将扩展名放在资源名称中,即

[bundle pathForResource:@"song1" ofType:@"mp3"]; // correct
[bundle pathForResource:@"song1.mp3" ofType:@"mp3"]; // wrong — gets song1.mp3.mp3.

检查valuem不带有任何扩展名。

于 2010-03-25T09:37:48.043 回答
0

对不起我之前的帖子,这里更清楚地重述了这个问题:

Vladimir:是的,我记录了 valuem,它给出了正确的字符串

KennyTM:是的,这是一个错字,在原始代码中只有@"song1"

问题是,如果我使用

[[NSBundle mainBundle] pathForResource:"song1" ofType:@"mp3"];  It is working 

但是如果我使用

[[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"];  

没有工作注意 value 是带有 @"song1" 的字符串

于 2010-03-25T21:08:06.357 回答