I believe that the best solution is to start NSTimerwhen the game starts AVAudioPlayer. You can set the timer to fire every half second or so. Then each time your timer fires, look at the property currentTimeon your audio player.
To do something at regular intervals, I would suggest that you save the instance variable for the playback time from the last call to the timer call. Then, if you have passed a critical point between the last callback and this, do your action.
So, in the pseudo code, the timer callback:
- Get
currentTimeyour AVAudioPlayer - Check if
currentTime criticalPoint - If yes, check if less
lastCurrentTime criticalPoint - If so, do your thing.
- Set
lastCurrentTimetocurrentTime
source
share