gpt4 book ai didi

ios - 表达式结果未在for循环中使用

转载 作者:行者123 更新时间:2023-12-03 02:05:00 25 4
gpt4 key购买 nike

我一天中的大部分时间都花在研究另一个音频文件播放完之后如何播放音频文件上。

我试过了audioPlayerDidFinishPlaying,但由于播放其他音频文件时它播放了第二个音频文件,所以我获得了有限的成功。因此,它会在播放任何音频文件时播放,而我希望仅在播放特定音频文件时播放。我还发现,在某些设备上,音频卡在了一个循环中,因此它会处理被触发在audioPlayerDidFinishPlaying中播放的文件,然后再次播放该文件。

无论如何,这整天使我心烦意乱,我被粉碎了。

无论如何,我已经找到了一种解决方案,并且可以完美地满足我的需求,但是我收到警告,说我无法解决。

NSArray  *theSoundArray = [NSArray arrayWithObjects:@"dog-00-voice",@"dog-00",nil];

int totalSoundsInQueue = [theSoundArray count];

for (int i=0; i < totalSoundsInQueue; i ) {

NSLog(@"%d", i);

NSString *sound = [theSoundArray objectAtIndex:i];

// Wait until the audio player is not playing anything
while(![arraySounds isPlaying]){

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:sound ofType:@"mp3"]] error:NULL];
self.arraySounds = player;
[arraySounds setVolume:1.0f];
[arraySounds play];
i++;
NSLog(@"%d", i);
}
}

这可行,但是我在for循环行的末尾收到有关i的警告。 “表达结果未使用”。

任何人都可以帮助我解决这个问题,或就如何使audioPlayerDidFinishPlaying像上面说明的那样为我提供建议。

提前致谢

最佳答案

您可以通过从此处删除该i来做到这一点:

for (int i=0; i < totalSoundsInQueue; )
{
...
}

您也可以通过编写 i = i来修复它,但这是不必要的,不建议这样做。

关于ios - 表达式结果未在for循环中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180940/

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