2015-01-05 80 views
0

我在我的project.the场景停留在AVAudioPlayer时, 在CollectionViewController的“didSelectItemAtIndexPath”的方法,我alloc和初始化AVAudioPlayer像波纹管,AVAudioPlayer为零后,我的Alloc初始化

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 .. 第一,我想未做的player.but没有运气财产.... 所以我尽量用this

+0

你仔细检查urlPath是不是零? –

+0

@WorldOfWarcraft“urlPath”不是零.. – Vats

+0

你把你的代码放在'didSelectItemAtIndexPath'中,这意味着只有当你选择了播放器的init。 –

回答

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


    }