Sound overlapping with multiple button presses

前端 未结 6 1549
野的像风
野的像风 2020-11-29 13:56

When I press a button, then press another one, the sounds overlap. How can I fix that so the first sound stops when another one is pressed?

 - (void)playOnce         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 14:39

    Add a check to see if the player is already playing at the beginning of each method:

    if (theAudio.playing == YES) {
        [theAudio stop];
    }
    

    AVAudioPlayer Class Reference

提交回复
热议问题