简体   繁体   中英

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 substringToIndex:[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, ie

[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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM