I have 114 audio files named from "0" to "113". Now AVAudioPlayer
will load the audio file depends on which row is been selected by the user. For example if user selects row at indexPath 0, "0.mp3" file will be loaded. Now to make it work, i am trying to convert the NSInteger*_selectedRow
value into String value and use this String value as audio file path for AVAudioPlayer
. But my app gives error of "Nil" value of String Error and get crashed. i might have done something stupid.
This is what i have tried
-(viewDidLoad){
NSString *selectRow=[NSString stringWithFormat:@"%d",_selectedRow];
NSLog(@"Value %@",selectRow);//this is working
[self audioFilling:selectRow];
}
- (void)audioFilling:(NSString*)value{
NSError *error;
// this audioFilePath is getting Nil for pathFor Resource
NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:value ofType:@"mp3"];
NSURL *pathAsURL = [[NSURL alloc] initFileURLWithPath:audioFilePath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:pathAsURL error:&error];
NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:(NSString*)value ofType:@"txt"]
encoding:NSUTF8StringEncoding
error:nil];
timeArray=[fileString componentsSeparatedByString:@"\n"];
}