-1

当用户选择集合视图自定义单元格时,我想播放 mp3 文件文件。但它不玩。这是我为此目的编写的代码 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

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

}

4

2 回答 2

0

一旦像这样尝试,一旦检查它是否存在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];
于 2013-05-18T14:43:22.100 回答
0

选中此复选框。还尝试将您的播放器存储为类属性。当声明为函数属性时,它可以释放。

于 2019-05-07T21:28:11.000 回答