ios - How to call an action while AVAudio is playing at a specific time? -


i know how call action while avaudio playing @ specific time.

let's avaudio hits "19 seconds" of playing call action of whatever want.

you use avplayer so, avplayer has method add addperiodictimeobserverforinterval. notice time interval 19, 1 means block gets called every 19 seconds. can make such perform task first 19th second.

player = avplayer(url: nsbundle.mainbundle().urlforresource("uptown", withextension: "mp3")!)  player.addperiodictimeobserverforinterval(cmtimemake(19, 1), queue: dispatch_get_main_queue()) { time in // perform task here  }  player.play() 

Comments