ios - How would I convert these four lines of code from AVAudioPlayer to AVPlayer? -


i need change code avaudioplayer avplayer because supports rewind , avaudioplayer doesn't. im having trouble these 4 lines of code seeks audio thats playing using slider. here code have:

func changeaudiotime() {      //musicplayer declared avaudioplayer , want change  avplayer , named variable player      musicplayer.preparetoplay()     musicplayer.currenttime = nstimeinterval(slider.value)     musicplayer.numberofloops = -1     slider.value = float(musicplayer.currenttime)  } 

for setting time in both case can use this:

self.player.seektotime(cmtimemake(int64(slider.value),1)) slider.value = float(cmtimegetseconds(self.player.currenttime())) 

for looping may try this, there no direct method of loop, till want repeat may set flag/observer , repeat song if repeat off can don't execute observer/seek

nsnotificationcenter.defaultcenter().addobserver(self, selector: "playeritemdidreachend:",name: avplayeritemdidplaytoendtimenotification, object: self.player.currentitem)  func playeritemdidreachend(notification: nsnotification) {     self.player.seektotime(kcmtimezero)     self.player.play() } 

Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -