开发者

Iphone SDK: pathFoResource:Nsstring problem -> playin MP3 files

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 substringT开发者_Python百科oIndex:[cellValue0 length] - 4];


 NSString *pdfPath2 = [[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"];  
 NSURL *url = [NSURL fileURLWithPath:pdfPath2];


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.


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜