2013-05-18 2 views
-1

사용자가 컬렉션보기 사용자 정의 셀을 선택하면 mp3 파일을 재생하고 싶습니다. 하지만 그것은 재생되지 않습니다. (UICollectionView *) collectionView didSelectItemAtIndexPath : 한 번 (NSIndexPath *) indexPath {iOS에서 uicollectionviewcell을 클릭하면 오디오 재생

NSLog(@"cell selected "); 
    AVAudioPlayer * audioPlayer; 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bismillah" ofType:@"mp3"]; 
    NSURL *audioUrl=[NSURL fileURLWithPath:path]; 
    audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:audioUrl error:nil]; 
    //audioPlayer.delegate=self; 
    [audioPlayer play]; 
    // cell.backgroundColor = [UIColor blueColor]; 

}

답변

0

번과 같이 시도하고 (무효) collectionView - 여기 내가이 목적 위해 작성한 코드입니다 수표가 bundle Resources에 있는지 확인하십시오.

NSString *audio=[[NSBundle mainBundle]pathForResource:@"Ranz des Vaches" ofType:@"mp3"]; 
NSURL *url=[[NSURL alloc]initFileURLWithPath:audio]; 
avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil]; 
avPlayer.delegate = self; 
[avPlayer prepareToPlay]; 
[avPlayer play]; 
+0

아직 작동하지 않습니다 ... 컬렉션보기 셀을 선택하면 오디오를 재생하는 데 필요한 단계를 나열 해주십시오. – atti

+0

번들 리소스 파일을 체크 했습니까? – Balu

+0

예. bismillah.mp3이 내 프로젝트 폴더에 있습니다. – atti