Iphone SDK:pathFoResource:Nsstring问题->播放 MP3 文件

发布于 2024-08-26 16:30:25 字数 627 浏览 9 评论 0原文

我试图在资源文件夹中获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸢与 2024-09-02 16:30:25

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

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

检查valuem不带任何扩展名。

Don't put the extension in the resource name, i.e.

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

Check that valuem does not carry any extensions.

假扮的天使 2024-09-02 16:30:25

对我之前的帖子感到抱歉,这里用更清晰的术语重述了问题:

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

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

问题是
如果我使用

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

但是如果我使用

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

它不起作用
请注意,该值是一个带有@“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

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

BUT If i use

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

It is NOT working
note that value is a string with @"song1"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文