我在我的项目中遇到了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
答案 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];
}