繁体   English   中英

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

[英]expression result unused on for loop

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

我试过了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来解决它,但这是不必要的,不建议这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM