【问题标题】:Iphone SDK: pathFoResource:Nsstring problem -> playin MP3 filesIphone SDK: pathFoResource:Nsstring 问题 -> 播放 MP3 文件
【发布时间】:2010-03-25 09:30:47
【问题描述】:

我试图在资源文件夹中获取 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];

【问题讨论】:

  • 尝试记录 valuem 以检查它是否具有预期值...

标签: iphone nsstring nsbundle


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    对不起,我之前的帖子,这里是更清晰的问题重述:

    弗拉基米尔: 是的,我记录了 valuem,它给出了正确的字符串

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

    问题是 如果我使用

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

    但是如果我使用

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

    它不工作 注意 value 是一个带有 @"song1"

    的字符串

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 2011-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      相关资源
      最近更新 更多