菜鸟教程小白 发表于 2022-12-11 19:40:36

ios - 如何解决除一个之外的所有问题


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

<pre><code>for player in audioPlayerBT{ player.stop()}
audioPlayerBT.numberOfLoops = -1
audioPlayerBT.play()
</code></pre>

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

<p>你能从 </p> 中排除一个索引吗

<pre><code>for player in audioPlayerBT{ player.stop()}
</code></pre>

<p>为了在启动新声音后使用它?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您想避免阻止特定玩家,请考虑:</p>

<pre><code>for (index, player) in audioPlayerBT.enumerated() {
    if index != playedNote {
      player.stop()
    }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何解决除一个之外的所有问题,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44007557/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44007557/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何解决除一个之外的所有问题