0

i'm stuck at AVAudioPlayer in my project.the scenario is, in CollectionViewController's "didSelectItemAtIndexPath" method, i alloc and init AVAudioPlayer like bellow,

dict=[plist objectAtIndex:indexPath.item];

    NSURL* urlPath=[NSURL new];
    urlPath=[NSURL URLWithString:[dict objectForKey:@"FilePath"]];
     NSError *error = nil;
    self.player=[[AVAudioPlayer alloc]initWithContentsOfURL:urlPath error:&error];
    NSLog(@"Error[%@]",[error localizedDescription]);
    [self.player setDelegate:self];
    [self.player prepareToPlay];

but after this,it still remains nill.. first, i tried without making property of player.but no luck.... so i try with this

Community
  • 1
  • 1
Vatsal Shukla
  • 1,274
  • 12
  • 25

1 Answers1

1

try like this

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath  {


    NSLog(@" selected data ==%@",[yoururlarray objectAtIndex: indexPath.row]);

 urlPath=[yoururlarray objectAtIndex: indexPath.row]);

    self.player=[[AVAudioPlayer alloc]initWithContentsOfURL:urlPath error:nil];
    [self.player setDelegate:self];
    [self.player prepareToPlay];


    }
Sport
  • 8,570
  • 6
  • 46
  • 65