I am trying to implement an on-off switch in playing multiple AKPlayers. First, I have called two AKPlayers
, triggered by AKCallbackInstruments
in AKSequencer
.
When I turn the switch on, 1) two AKPlayers are assigned to AKMixer, 2) Audiokit starts, 3) Two tracks are added to AKSequencer, 4) Sequencer starts.
And when turn off, 1) two AKPlayers.stop()
, 2) sequencer.stop()
3) sequencer.deleteTrack(trackIndex: 0)
, sequencer.deleteTrack(trackIndex:1)
4) AudioKit.stop()
.
First on and off works successfully. But when I turn the switch on for the second time, the music is getting louder and louder, possibly because some midi tracks/sequencer tracks are not removed completely. Can anybody tell me what I’m missing here? Much appreciated. <3