iphone - How can you play a sound of a specified duration using AVAudioPlayer on iOS? -


i want play specified duration within sound file on ios. found method in avaudioplayer seeks begining of playing (playattime:) cannot find direct way specify end time before end of sound file.

is there way achieve this?

if don't need precision , want stick avaudioplayer, 1 option:

- (void)playattime:(nstimeinterval)time withduration:(nstimeinterval)duration {     nstimeinterval shortstartdelay = 0.01;     nstimeinterval = player.devicecurrenttime;      [self.audioplayer playattime:now + shortstartdelay];     self.stoptimer = [nstimer scheduledtimerwithtimeinterval:shortstartdelay + duration                                                        target:self                                                      selector:@selector(stopplaying:)                                                     userinfo:nil                                                      repeats:no]; }  - (void)stopplaying:(nstimer *)thetimer {     [self.audioplayer pause]; } 

bear in mind stoptimer fire on thread's run loop, there variability in how long audio plays, depending on else app doing @ time. if need higher level of precision, consider using avplayer instead of avaudioplayer. avplayer plays avplayeritem objects, let specify forwardplaybackendtime.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -