【问题标题】:How to address all except one如何解决除一个之外的所有问题
【发布时间】:2017-10-15 21:29:09
【问题描述】:

在我的 Swift iOS 应用中,我需要快速播放不同的声音。每个触发的声音都需要停止所有其他声音,因此一次只播放一个声音。 我用过

for player in audioPlayerBT{ player.stop()}
audioPlayerBT[playedNote].numberOfLoops = -1
audioPlayerBT[playedNote].play()

在开始新声音之前停止所有声音。这确实有效,但有一个非常非常短的暂停。我想在停止其他声音之前开始新声音以使其更流畅。

你能从

中排除一个索引吗
for player in audioPlayerBT{ player.stop()}

为了在启动新声音后使用它?

【问题讨论】:

    标签: ios swift audio avplayer


    【解决方案1】:

    如果您想避免阻止特定玩家,请考虑:

    for (index, player) in audioPlayerBT.enumerated() {
        if index != playedNote {
            player.stop()
        }
    }
    

    【讨论】:

    • 嘿,这看起来像我需要的,但它不起作用。 “无法调用非功能类型 'AudioPlayer' 的值 推荐修复从 audioPlayerBT() 中删除 () 但没有它我得到:“表达式类型 '[AVAudioPlayer]' 在没有更多上下文的情况下是不明确的”
    • @MarcelFriedmann 抱歉,在复制和粘贴中有些内容被打乱了。再试一次……
    • 谢谢,就是这样,你是明星!!
    • 或:for (index, player) in audioPlayerBT.enumerated() where index != playedNote { .. }
    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    相关资源
    最近更新 更多