gpt4 book ai didi

iphone - iPhone AVAudioFoundation声音完成循环

转载 作者:行者123 更新时间:2023-12-03 01:02:54 26 4
gpt4 key购买 nike

是否可以在继续执行代码之前强制音频文件完成播放?在下面的示例中,我希望音频文件可以播放的次数与数组中的项的播放次数相同。当前它完成循环仅播放一次。我在AVFoundation框架内使用AVAudioPlayer。

for (int i = 0; i<[Array count]; i++) {
if ([Array objectAtIndex:i] == @"Red") {
NSLog(@"red");
[self.player play];
}
if ([Array objectAtIndex:i] == @"Blue") {
NSLog(@"blue");
[self.player play];
}
if ([Array objectAtIndex:i] == @"Green") {
NSLog(@"green");
[self.player play];
}
if ([Array objectAtIndex:i] == @"Yellow") {
NSLog(@"yellow");
[self.player play];
}
}

我还使用了audioPlayerDidFinishPlaying方法来测试它是否完成了五次,但是只能达到一次此方法。
-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL) completed{
if ((completed) == YES){
NSLog(@"audio finish");
return;
}
}

播放音频时是否可以将for循环保持在适当的位置?

理论上,控制台应显示为:color-> audio finish-> color-> audio finish-> repe

最佳答案

也许您可以在收到finishPlaying通知时告诉AudioPlayer播放,例如:

int arrayIndex = 0
NSArray* array; //initialized somewhere..


-(void)myFunction
{
if(arrayIndex < [array length])
{
NSArray* colors = [NSArray arrayWithObjects:@"Red",@"Blue",@"Green",@"Yellow",nil];
if( [colors indexOf:[array objectAtIndex:arrayIndex]] != NSNotFound )
{
NSLog( [array objectAtIndex:arrayIndex] );
[self.player play];
}
arrayIndex++;
}else{
NSLog(@"audio finish");
}
}

-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL) completed{
if ((completed) == YES){
[self myFunction];
}
}

-(void)start_it_up
{
arrayIndex = 0;
[self myFunction];
}

关于iphone - iPhone AVAudioFoundation声音完成循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com