audio - Swift function playAtTime() Does Not Add Delay -
i'm trying play 2 audioplayers, 1 after other has finished playing. i'm using swift function playattime() create delay second, follows:
var audioplayer1 = avaudioplayer() var audioplayer2 = avaudioplayer() let soundpatha = nsbundle.mainbundle().pathforresource("a", oftype: "m4a") let soundurla = nsurl.fileurlwithpath(soundpatha!) let soundpathb = nsbundle.mainbundle().pathforresource("b", oftype: "m4a") let soundurlb = nsurl.fileurlwithpath(soundpathb!) var notea = sound() notea.url = soundurla var noteb = sound() noteb.url = soundurlb self.audioplayer1 = try!avaudioplayer(contentsofurl: soundurla) self.audioplayer2 = try!avaudioplayer(contentsofurl: soundurlb) let duration : nstimeinterval = audioplayer1.duration self.audioplayer1.play() self.audioplayer2.playattime(duration)
however, no delay occurs. issue here?
the playattime
function not start play @ given time. instead plays immediately, given time in sound played. if give 0.6, start playing straight away, sound start 0.6 seconds in. see documentation here.
if want wait before playing, use dispatch_after
:
let delaytime = dispatch_time(dispatch_time_now, int64(0.6 * double(nsec_per_sec))) dispatch_after(delaytime, dispatch_get_main_queue()) { self.audioplayer2.play() }
Comments
Post a Comment