views:

147

answers:

2

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];
+1  A: 

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.

KennyTM
A: 

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 valuem is a string with @"song1"

Thanks a lot

Kaya