在我分配init之后,AVAudioPlayer是零

时间:2015-01-05 07:26:45

标签: objective-c iphone ios8 xcode6 avaudioplayer

我在我的项目中遇到了AVAudioPlayer。情节是, 在CollectionViewController" didSelectItemAtIndexPath"方法,我分配和初始AVAudioPlayer像贝娄,

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];

但在此之后,它仍然是nill .. 首先,我尝试没有制作播放器的属性。但没有运气.... 所以我试试this

1 个答案:

答案 0 :(得分:1)

试试这个

-(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];


    }